Is there any way to use inline functions in postgREST?
有没有办法在postgREST中使用内联函数?
Something similar to:
类似于:
https://api.example.com/mytable?select=id,geom:ST_AsEWKT(geom)
in this notation i recieve an error:
在这个符号中,我收到一个错误:
Searched for a foreign key relationship between 'mytable' and 'ST_AsEWKT' in the schema 'public', but no matches were found.
I need quite a simple query:
我需要一个非常简单的问题:
SELECT id, ST_AsEWKT(geom) AS geom FROM mytable
ST_AsEWKT returns different representation of geom column.
ST_AsEWKT返回geom列的不同表示形式。
Clean workaround is to use VIEWS with predefined columns:
干净的解决方法是使用带有预定义列的视图:
CREATE VIEW vmytable AS SELECT id, ST_AsEWKT(geom) AS geom FROM mytable;
And then use posgREST api call on View table
然后对View表使用posgREST api调用
https://api.example.com/vmytable?select=id,geom
更多回答
优秀答案推荐
you can use subquery
您可以使用子查询
SELECT id, (SELECT ST_AsEWKT(geom) FROM mytable) AS geom
You can also use a JSONPath expression to achieve the same result.
您也可以使用JSONPath表达式来实现相同的结果。
SELECT id, $.geom FROM mytable
You can use a computed field for this case:
在这种情况下,可以使用计算字段:
CREATE FUNCTION ewkt_geom(anyelement)
RETURNS text AS $$
SELECT $1.geom;
$$ LANGUAGE SQL;
Then do:
然后执行以下操作:
https://api.example.com/vmytable?select=id,ewkt_geom
更多回答
Thank you for your answer but I'm searching for a solution using postgREST HTTP GET QUERY not SQL.
谢谢你的回答,但我正在寻找一个使用postgREST HTTP GET查询而不是SQL的解决方案。
我是一名优秀的程序员,十分优秀!