Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36288
| Date | 2013-01-06 16:44 -0500 |
|---|---|
| From | Mitya Sirenef <msirenef@lightbird.net> |
| Subject | Re: psycopg2 cursor.execute CREATE TABLE issue |
| References | <185b6d9e-99ce-4f2a-81ea-d9a63b81b4cf@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.186.1357508694.2939.python-list@python.org> (permalink) |
On Sun 06 Jan 2013 04:38:29 PM EST, andydtaylor@gmail.com wrote:
> Hi all,
>
> I'm trying to create a process which will create a new table and populate it.
>
> But something is preventing this from working, and I don't know enough to figure it out, despite having spent most of today reading up. The code executes with no error, yet no table is created or populated.
>
> Can anyone offer me some advice? code below.
>
> Thanks,
>
> Andy
>
> #!/usr/bin/python
> import psycopg2
> import sys
>
> def main():
> db = psycopg2.connect(
> host = 'localhost',
> database = 'gisdb',
> user = 'postgres',
> password = 'L1ncoln0ut@'
> )
> cursor = db.cursor()
> cursor.execute("CREATE TABLE test (id serial PRIMARY KEY, num integer, data varchar);")
> cursor.execute("INSERT INTO test (num, data) VALUES (%s, %s)",(100, "abc'def"))
>
> if __name__ == "__main__":
> main()
To commit a transaction, you need to do a db.commit() call.
-m
--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
psycopg2 cursor.execute CREATE TABLE issue andydtaylor@gmail.com - 2013-01-06 13:38 -0800
Re: psycopg2 cursor.execute CREATE TABLE issue Mitya Sirenef <msirenef@lightbird.net> - 2013-01-06 16:44 -0500
Re: psycopg2 cursor.execute CREATE TABLE issue Walter Hurry <walterhurry@lavabit.com> - 2013-01-06 22:37 +0000
Re: psycopg2 cursor.execute CREATE TABLE issue Chris Angelico <rosuav@gmail.com> - 2013-01-07 08:45 +1100
Re: psycopg2 cursor.execute CREATE TABLE issue andydtaylor@gmail.com - 2013-01-06 13:53 -0800
Re: psycopg2 cursor.execute CREATE TABLE issue Mitya Sirenef <msirenef@lightbird.net> - 2013-01-06 17:14 -0500
Re: psycopg2 cursor.execute CREATE TABLE issue Chris Angelico <rosuav@gmail.com> - 2013-01-07 09:19 +1100
Re: psycopg2 cursor.execute CREATE TABLE issue andydtaylor@gmail.com - 2013-01-06 13:53 -0800
csiph-web