best way to get autogenerated primary key
Hi, this is my first post to this list, so forgive me if this is not the right place to post this. I tried to do my research (google, monetdb.org, python api help) but didn't find an answer. How can I get the auto-generated primary key (integer) after executing an insert. I want to use it in a second insert to another table that references the first. (in PostgreSQL I used the RETURNING clause for this) thanks in advance Mate
The getGeneratedKeys() method on Statement and PreparedStatement should do
the trick:
http://docs.oracle.com/javase/6/docs/api/java/sql/Statement.html#getGenerate...)
Cheers,
Percy
On Mon, Jan 28, 2013 at 7:11 PM, Mate Birkas
Hi, this is my first post to this list, so forgive me if this is not the right place to post this. I tried to do my research (google, monetdb.org, python api help) but didn't find an answer.
How can I get the auto-generated primary key (integer) after executing an insert. I want to use it in a second insert to another table that references the first.
(in PostgreSQL I used the RETURNING clause for this)
thanks in advance Mate
_______________________________________________ users-list mailing list users-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/users-list
-- Percy Wegmann +1 512 637 8500 ext 148
Thanks,
but there seems to be no Statement class in the Python API. Any search on
'getGeneratedKeys' (google, grep over the source) yields nothing. Is there
a way to do it in Python?
Mate
On Tue, Jan 29, 2013 at 2:47 AM, Percy Wegmann
The getGeneratedKeys() method on Statement and PreparedStatement should do the trick:
http://docs.oracle.com/javase/6/docs/api/java/sql/Statement.html#getGenerate...)
Cheers, Percy
On Mon, Jan 28, 2013 at 7:11 PM, Mate Birkas
wrote: Hi, this is my first post to this list, so forgive me if this is not the right place to post this. I tried to do my research (google, monetdb.org, python api help) but didn't find an answer.
How can I get the auto-generated primary key (integer) after executing an insert. I want to use it in a second insert to another table that references the first.
(in PostgreSQL I used the RETURNING clause for this)
thanks in advance Mate
_______________________________________________ users-list mailing list users-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/users-list
--
Percy Wegmann +1 512 637 8500 ext 148
_______________________________________________ users-list mailing list users-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/users-list
Hi Mate,
I should learn to read :)
Try cursor.lastrowid.
I took a look at the implementation of the Java and Python APIs. The Java
API looks for a Q_UPDATE header (int value 50) in the MAPI response to grab
the last generated key. The cursors.py file mentions this same header and
looks like it's putting a value in the field "lastrowid". So, you may try
accessing lastrowid on the cursor object to see if that gets you what you
need. I haven't actually used the Python API, so I'm just guessing based
on the source code.
Cheers,
Percy
On Mon, Jan 28, 2013 at 8:45 PM, Mate Birkas
Thanks, but there seems to be no Statement class in the Python API. Any search on 'getGeneratedKeys' (google, grep over the source) yields nothing. Is there a way to do it in Python? Mate
On Tue, Jan 29, 2013 at 2:47 AM, Percy Wegmann
wrote: The getGeneratedKeys() method on Statement and PreparedStatement should do the trick:
http://docs.oracle.com/javase/6/docs/api/java/sql/Statement.html#getGenerate...)
Cheers, Percy
On Mon, Jan 28, 2013 at 7:11 PM, Mate Birkas
wrote: Hi, this is my first post to this list, so forgive me if this is not the right place to post this. I tried to do my research (google, monetdb.org, python api help) but didn't find an answer.
How can I get the auto-generated primary key (integer) after executing an insert. I want to use it in a second insert to another table that references the first.
(in PostgreSQL I used the RETURNING clause for this)
thanks in advance Mate
_______________________________________________ users-list mailing list users-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/users-list
--
Percy Wegmann +1 512 637 8500 ext 148
_______________________________________________ users-list mailing list users-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/users-list
_______________________________________________ users-list mailing list users-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/users-list
-- Percy Wegmann +1 512 637 8500 ext 148
Thanks Percy!
cursor.lastrowid is exactly what I was looking for. (And I learned that
attribute docstrings are not presented by help() .) Next time I will read
the source more thoroughly.
Thanks again!
Mate
On Tue, Jan 29, 2013 at 4:34 AM, Percy Wegmann
Hi Mate,
I should learn to read :)
Try cursor.lastrowid.
I took a look at the implementation of the Java and Python APIs. The Java API looks for a Q_UPDATE header (int value 50) in the MAPI response to grab the last generated key. The cursors.py file mentions this same header and looks like it's putting a value in the field "lastrowid". So, you may try accessing lastrowid on the cursor object to see if that gets you what you need. I haven't actually used the Python API, so I'm just guessing based on the source code.
Cheers, Percy
On Mon, Jan 28, 2013 at 8:45 PM, Mate Birkas
wrote: Thanks, but there seems to be no Statement class in the Python API. Any search on 'getGeneratedKeys' (google, grep over the source) yields nothing. Is there a way to do it in Python? Mate
On Tue, Jan 29, 2013 at 2:47 AM, Percy Wegmann
wrote: The getGeneratedKeys() method on Statement and PreparedStatement should do the trick:
http://docs.oracle.com/javase/6/docs/api/java/sql/Statement.html#getGenerate...)
Cheers, Percy
On Mon, Jan 28, 2013 at 7:11 PM, Mate Birkas
wrote: Hi, this is my first post to this list, so forgive me if this is not the right place to post this. I tried to do my research (google, monetdb.org, python api help) but didn't find an answer.
How can I get the auto-generated primary key (integer) after executing an insert. I want to use it in a second insert to another table that references the first.
(in PostgreSQL I used the RETURNING clause for this)
thanks in advance Mate
_______________________________________________ users-list mailing list users-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/users-list
--
Percy Wegmann +1 512 637 8500 ext 148
_______________________________________________ users-list mailing list users-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/users-list
_______________________________________________ users-list mailing list users-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/users-list
--
Percy Wegmann +1 512 637 8500 ext 148
_______________________________________________ users-list mailing list users-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/users-list
On 01/29/2013 04:34 AM, Percy Wegmann wrote:
Hi Mate,
I should learn to read :)
Try cursor.lastrowid.
Yep. The MonetDB Python API follows PEP-0249: http://www.python.org/dev/peps/pep-0249/#lastrowid greetings, -- Gijs Molenaar http://www.astro.uva.nl/people/gijs-molenaar/
participants (3)
-
Gijs Molenaar
-
Mate Birkas
-
Percy Wegmann