PG will give back the value of a newly inserted SERIAL value by calling " SELECT currval('sequencename') ". If this is issued inside the same transaction as the INSERT, it's race-condition free. I believe the reason pyscopg doesn't do this to set cursor.lastrowid, is
a) - there may be more than one SERIAL column on the row, and no way to determine which is the "row id"
b) - won't work in autocommit mode
But here we presumably have both the knowledge of what the id is (it's the PK), and at least some control over transaction status, so it might be possible to use it.
Rick
On 2/18/06, Michael Bayer <[EMAIL PROTECTED]> wrote:
apparently, by "fixed" i meant "largely improved". continuing on
the theme of postgres primary keys, I had to just break the rule of
"PassiveDefaults are executed implicitly by the database" just now in
the case of primary key columns with Postgres....since for PG I need
to pre-execute those just like a sequence (and back to the chorus -
"cuz postgres/psycopg wont give me back an inserted row.......")
changeset 984 fixes this in postgres.py, with unit test added in test/
query.py QueryTest.testpassiveoverride.
On Feb 17, 2006, at 5:47 PM, Luís Bruno wrote:
> Hello,
>
> I was expecting the following to work, because I have a faint
> recollection of seeing it advertised on the list as fixed. Maybe my
> brain is playing tricks on me?
>
>> psycopg2.ProgrammingError: null value in column "speedy_user_id"
>> violates not-null constraint
>
> I'm using psycopg2-trunk and sqlalchemy-trunk
>
> --- 8< ---
>
> from sqlalchemy import *
>
> class User(object):
> # CREATE TABLE speedy_users
> # (
> # speedy_user_id SERIAL PRIMARY KEY,
> #
> # user_name VARCHAR NOT NULL UNIQUE,
> # user_password VARCHAR NOT NULL
> # );
> pass
>
> engine = create_engine('postgres://database=lbruno');
> users_table = Table('speedy_users', engine, autoload=True);
> assign_mapper(User, users_table)
>
> u = User()
> u.user_name = 'lbruno'
> u.user_password = 'random'
>
> objectstore.commit()
>
> --- 8< ---
>
> There's also the possibility I'm reading the docs wrong, of course.
> Please flame me accordingly if so.
>
> Thanks,
> --lbruno
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through
> log files
> for problems? Stop! Download the new AJAX search engine that makes
> searching your log files as easy as surfing the web. DOWNLOAD
> SPLUNK!
> http://sel.as-us.falkag.net/sel?
> cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Sqlalchemy-users mailing list
> Sqlalchemy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmdlnk&kid3432&bid#0486&dat1642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users