Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-16 Thread Adrien Berchet
This works perfectly, thank you very much! With this example I understood much better how the compiles() function works. I had to update your example to make it work in GeoAlchemy2 but everything seems ok now. See https://github.com/geoalchemy/geoalchemy2/pull/258 Thanks again! Le mer. 15 avr.

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-15 Thread Mike Bayer
so the attached script includes what I was suggesting, which is that when this table or mapped class comes in, you get that into a ColumnElement right away, that way the function internals treat it like any other column; the code fails otherwise in current development SQLAlchemy versions that

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-15 Thread Adrien Berchet
Yes, the first query: > select([func.ST_AsGeoJSON(Lake.__table__.c.geom)]) > returns only the geometry part of a GeoJson: { "type": "LineString", "coordinates": [[0, 0], [1, 1]] } while the query: > select([func.ST_AsGeoJSON(Lake, 'geom')]) > returns a complete GeoJson

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-15 Thread Mike Bayer
working on this now, just a quick question, is there an actual difference between select([func.ST_AsGeoJSON(Lake.__table__.c.geom)]) and select([func.ST_AsGeoJSON(Lake, 'geom')]) ? that is, users definitely need this goofy "Table" syntax, right? On Wed, Apr 15, 2020, at 7:15 AM, Adrien

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-15 Thread Adrien Berchet
Ok, thank you for your advice, following it I tried the following (in geoalchemy2.functions.py). class ST_AsGeoJSON(functions.GenericFunction): > > def __init__(self, *args, **kwargs): > args = list(args) > self.feature_mode = False > for idx, elem in enumerate(args):

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-14 Thread Mike Bayer
OK so use the "t" form with the "geom" name sent as a string, it wants the whole row so this is a special Postgresql syntax. There are many ways to make it output this and it depends on the specifics of how this is being rendered. it may require a custom construct with a @compiles rule as I

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-14 Thread Adrien Berchet
This function is defined here: https://github.com/postgis/postgis/blob/7f4426716f561187175d73bfff330343b25a7be9/postgis/postgis.sql.in#L4609 And its C implementation is here: https://github.com/postgis/postgis/blob/b48fb3e2272568aa6310fc26aefc69010d4f37e3/postgis/lwgeom_out_geojson.c#L79 Its

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-14 Thread Mike Bayer
does this ST_AsGeoJSON function hardcode itself to look for column names "id" and "geom" ? it's not going to be any easier to get SQLAlchemy to render "t" than it is "t.*". it wants to name columns. On Tue, Apr 14, 2020, at 9:45 AM, Adrien Berchet wrote: > I just found that in fact it is

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-14 Thread Adrien Berchet
I just found that in fact it is possible to just pass the table name to ST_AsGeoJson, so the following query works: > SELECT ST_AsGeoJSON(t) > FROM t; > I will try to use this writing in GeoAlchemy2, though I don't know yet how to translate it in SQLAlchemy. Le mar. 14 avr. 2020 à 14:23, Mike

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-14 Thread Mike Bayer
and you can't say "SELECT t.d, t.geom" ? There really should be no difference between "t.*" and "t.id, t.geom". On Tue, Apr 14, 2020, at 5:31 AM, Adrien Berchet wrote: > The "column names" issue is that when we use ROW(), like in the following > query: >> SELECT ROW(t.id, t.geom) >> FROM

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-14 Thread Adrien Berchet
The "column names" issue is that when we use ROW(), like in the following query: > SELECT ROW(t.id, t.geom) > FROM (SELECT 1 AS id, ST_GeomFromText('POINT( 1 1)') AS geom) AS t; > we obtain the following result: > row > >

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-13 Thread Mike Bayer
On Mon, Apr 13, 2020, at 6:25 PM, Adrien Berchet wrote: > Hello there > > I tried to integrate your POC in GeoAlchemy2 in the following PR: > https://github.com/geoalchemy/geoalchemy2/pull/258 > > It is almost working but the ST_AsGeoJSON() function needs a record, not a > list of columns. So

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-04-13 Thread Adrien Berchet
Hello there I tried to integrate your POC in GeoAlchemy2 in the following PR: https://github.com/geoalchemy/geoalchemy2/pull/258 It is almost working but the ST_AsGeoJSON() function needs a record, not a list of columns. So the query should be like: > SELECT ST_AsGeoJSON(t.*) > FROM t; > >

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-01-20 Thread Mike Bayer
On Sun, Jan 19, 2020, at 12:23 PM, Stephan Hügel wrote: > > > On Sunday, 19 January 2020 16:13:40 UTC, Mike Bayer wrote: >> >> >> On Sun, Jan 19, 2020, at 11:10 AM, Mike Bayer wrote: >>> >>> >>> On Sun, Jan 19, 2020, at 10:54 AM, Stephan Hügel wrote: I'm trying to define a

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-01-19 Thread Stephan Hügel
On Sunday, 19 January 2020 16:13:40 UTC, Mike Bayer wrote: > > > > On Sun, Jan 19, 2020, at 11:10 AM, Mike Bayer wrote: > > > > On Sun, Jan 19, 2020, at 10:54 AM, Stephan Hügel wrote: > > I'm trying to define a GenericFunction that calls a PostGIS 3.0 function ( > ST_AsGeoJson

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-01-19 Thread Mike Bayer
On Sun, Jan 19, 2020, at 11:10 AM, Mike Bayer wrote: > > > On Sun, Jan 19, 2020, at 10:54 AM, Stephan Hügel wrote: >> I'm trying to define a GenericFunction that calls a PostGIS 3.0 function >> (ST_AsGeoJson ). The latest >> version can be called

Re: [sqlalchemy] Define a GenericFunction that passes all columns

2020-01-19 Thread Mike Bayer
On Sun, Jan 19, 2020, at 10:54 AM, Stephan Hügel wrote: > I'm trying to define a GenericFunction that calls a PostGIS 3.0 function > (ST_AsGeoJson ). The latest > version can be called in two different ways: > > SELECT ST_AsGeoJSON(t.geom) FROM foo

[sqlalchemy] Define a GenericFunction that passes all columns

2020-01-19 Thread Stephan Hügel
I'm trying to define a GenericFunction that calls a PostGIS 3.0 function ( ST_AsGeoJson ). 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