Created
May 27, 2012 07:25
-
-
Save emberian/2802595 to your computer and use it in GitHub Desktop.
Confusing psycopg2 behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(python)[kb1pkl@Ulysses:hacking/python]$ python (05-27 03:21) | |
Python 2.7.3 (default, Apr 30 2012, 21:18:11) | |
[GCC 4.7.0 20120416 (Red Hat 4.7.0-2)] on linux2 | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> import psycopg2 as pg | |
>>> conn = pg.connect('user=flyl dbname=flyl') | |
>>> c = conn.cursor() | |
>>> c.execute('INSERT INTO files (name, owner) VALUES (%s, %s) RETURNING id;', ("foo", "bar")) | |
>>> c.fetchall() | |
[(15,)] | |
>>> | |
(python)[kb1pkl@Ulysses:hacking/python]$ psql -U flyl -c "SELECT * FROM files;" (05-27 03:22) | |
id | name | owner | |
----+------+------- | |
(0 rows) | |
(python)[kb1pkl@Ulysses:hacking/python]$ psql -U flyl -c "INSERT INTO files (name, owner) VALUES ('foo', 'bar') RETURNING id;" | |
id | |
---- | |
16 | |
(1 row) | |
INSERT 0 1 | |
(python)[kb1pkl@Ulysses:hacking/python]$ psql -U flyl -c "SELECT * FROM files;" (05-27 03:23) | |
id | name | owner | |
----+------+------- | |
16 | foo | bar | |
(1 row) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm an idiot, forgot that I needed to commit.