I'm trying to define a GenericFunction that calls a PostGIS 3.0 function (
ST_AsGeoJson <https://postgis.net/docs/ST_AsGeoJSON.html>). The latest 
version can be called in two different ways:

SELECT ST_AsGeoJSON(t.geom) FROM foo as t WHERE t.id = 1;
SELECT ST_AsGeoJSON(t.*) FROM foo as t WHERE t.id = 1;

where the first example returns a GeoJSON Geometry, and the second returns 
a GeoJSON Feature. I'm only interested in making use of the second type / 
am happy to define the two variants separately.

I should be able to subclass GenericFunction in order to do this, but I'm 
missing two details:

1. What should the return type of my subclass be?
2. How can I specify that I want to pass the record / row / all columns, as 
opposed to just the geom column to the underlying function? Ordinarily, 
attempting something like 

sess.query(func.MyGeojson(Foo)).all()

Will give me an error:

Object <class 'models.Foo'> is not legal as a SQL literal value



-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/f3718ff7-a252-41a9-8ac4-1ee2ee1e7f9f%40googlegroups.com.

Reply via email to