On Sun, Oct 8, 2017 at 10:45 PM, Seth P <set...@outlook.com> wrote:
> Apologies if I missed something, but does SQLAlchemy (1.2.0?) support the new 
> Postgres 10 identity keyword 
> (https://blog.2ndquadrant.com/postgresql-10-identity-columns/)?

not directly, however you can intercept SERIAL and replace it with the
new syntax as follow:

from sqlalchemy.schema import CreateColumn
from sqlalchemy.ext.compiler import compiles


@compiles(CreateColumn, 'postgresql')
def use_identity(element, compiler, **kw):
    text = compiler.visit_create_column(element, **kw)
    text = text.replace("SERIAL", "INT GENERATED BY DEFAULT AS IDENTITY")
    return text

if __name__ == '__main__':

    from sqlalchemy import MetaData, Table, Column, Integer, String,
create_engine

    m = MetaData()

    t = Table(
        't', m,
        Column('id', Integer, primary_key=True),
        Column('data', String)
    )

    e = create_engine("postgresql://scott:tiger@pg10/test", echo=True)

    m.drop_all(e)
    m.create_all(e)


Adding a note to the docs now.




>
> --
> 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 post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to