Re: [sqlalchemy] Insert statement and DEFAULT keyword

2020-04-14 Thread Mike Bayer
oh, you're using insert.values() with multivalues. Sure, use a literal_column() for that, this is not a normal SQL thing. it won't scale to huge numbers because you will overflow the query buffer, unless you break them into batches. I might prefer to use the psycopg2 batch mode helpers instead

Re: [sqlalchemy] Insert statement and DEFAULT keyword

2020-04-14 Thread Nicolas Caniart
As you may have guessed the DEFAULT keyword is used to "even" the size of the tuples in the VALUES clause and explicitly asks the RDBMS to replace itself with the currently defined default value for the corresponding column. The RDBMS in question is Postgres (>=11). The context is we want to

[sqlalchemy] Re: Consolidate multiple one-to-one into a list

2020-04-14 Thread Jonathan Vanasco
This departs a bit from the example, because you are caching the youngest and oldest ids onto the Parent object. is that necessary for your usage? > Now my question is: how can I introduce a set/list of all children on the parent? The line you commented out from the example was either:

Re: [sqlalchemy] Insert statement and DEFAULT keyword

2020-04-14 Thread Mike Bayer
On Tue, Apr 14, 2020, at 10:41 AM, Nicolas Caniart wrote: > Hi ! > > I've been looking into the documentation but could not find it. > What is the proper way to insert a DEFAULT keywork in the tuples of the > VALUES clause in an INSERT statement ? As in > > CREATE TABLE number ( > i INTEGER,

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

[sqlalchemy] Insert statement and DEFAULT keyword

2020-04-14 Thread Nicolas Caniart
Hi ! I've been looking into the documentation but could not find it. What is the proper way to insert a DEFAULT keywork in the tuples of the VALUES clause in an INSERT statement ? As in CREATE TABLE number ( i INTEGER, letters STRING, roman STRING DEFAULT '', ) ; INSERT INTO number

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 > >

[sqlalchemy] Consolidate multiple one-to-one into a list

2020-04-14 Thread Jens Troeger
Hello, Taking the relationship examples from the documentation , suppose I have the following: class Parent(Base): __tablename__ = "parent" id = Column(Integer, primary_key=True) oldest_child_id = Column(Integer,