Re: [sqlalchemy] How to disable the integer col + pk = serial behaviour?

2020-08-05 Thread Mike Bayer
this is also exactly how its documented, it explicitly mentions PostgreSQL and SERIAL, see below. How did you come to be using the optional=True flag otherwise? https://docs.sqlalchemy.org/en/13/core/defaults.html?highlight=sequence#sqlalchemy.schema.Sequence.params.optional "boolean

Re: [sqlalchemy] How to disable the integer col + pk = serial behaviour?

2020-08-05 Thread Mike Bayer
On Wed, Aug 5, 2020, at 7:54 PM, zsol...@gmail.com wrote: > Thanks for all the answers. > > > add autoincrement=False to the Column > > This is actually all I needed, but possibly my findings can help others or > provide improvements. > > I'm not using drop_alll and create_all, but

Re: [sqlalchemy] How to disable the integer col + pk = serial behaviour?

2020-08-05 Thread zsol...@gmail.com
Thanks for all the answers. > add autoincrement=False to the Column This is actually all I needed, but possibly my findings can help others or provide improvements. I'm not using drop_alll and create_all, but table.create() and this results in the "relation "some_seq" already exists" error.

Re: [sqlalchemy] How to disable the integer col + pk = serial behaviour?

2020-08-05 Thread Mike Bayer
On Wed, Aug 5, 2020, at 9:25 AM, Zsolt Ero wrote: > But this would create a different id for each table, wouldn't it? if you want two tables to have the same sequence then use one Sequence object for both. If the Sequence is present on the Column it will not create SERIAL. I've tried to

Re: [sqlalchemy] Re: How to disable the integer col + pk = serial behaviour?

2020-08-05 Thread Mike Bayer
On Wed, Aug 5, 2020, at 9:07 AM, Zsolt Ero wrote: > I'm lost in two places: > > sa.Column( > 'trip_num', > sa.Integer, > sa.Sequence('trip_num_seq', schema='public', optional=True), > primary_key=True, > ) > > > 1. I'm specifying schema='public', yet the sequence gets created under >

Re: [sqlalchemy] How to disable the integer col + pk = serial behaviour?

2020-08-05 Thread Zsolt Ero
But this would create a different id for each table, wouldn't it? I'd like to use the same ids for matching rows, such that table A's primary key is the same as table B's primary key, so that they can join-ed together like when it was a single table. So far the only solution I found is to remove

Re: [sqlalchemy] How to disable the integer col + pk = serial behaviour?

2020-08-05 Thread Mike Bayer
On Wed, Aug 5, 2020, at 8:59 AM, Zsolt Ero wrote: > Hi, > > I've split a table into two tables, for performance reasons. I'd like to > insert into both tables using the same sequence. I'm inserting using > executemany_mode='values'. > > My idea is to call nextval() on the sequence before

Re: [sqlalchemy] How to disable the integer col + pk = serial behaviour?

2020-08-05 Thread 'Michael Mulqueen' via sqlalchemy
I've just done something like this the other day, but it was with an existing sequence. We're using Alembic for schema updates, so I'm not sure whether SQLAlchemy's built-in create_all would behave the same way. You should still be able to use a similar approach. shared_sequence =

[sqlalchemy] Re: How to disable the integer col + pk = serial behaviour?

2020-08-05 Thread Zsolt Ero
I'm lost in two places: sa.Column( 'trip_num', sa.Integer, sa.Sequence('trip_num_seq', schema='public', optional=True), primary_key=True, ) 1. I'm specifying schema='public', yet the sequence gets created under Metadata's schema. 2. I'm trying this optional=True, however all it does is

[sqlalchemy] How to disable the integer col + pk = serial behaviour?

2020-08-05 Thread Zsolt Ero
Hi, I've split a table into two tables, for performance reasons. I'd like to insert into both tables using the same sequence. I'm inserting using executemany_mode='values'. My idea is to call nextval() on the sequence before insert and fill in the values client side, before inserting. select