Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.nosignal.org!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'sys': 0.05; '"__main__":': 0.07; '__name__': 0.07; 'main()': 0.07; 'subject:skip:c 10': 0.07; 'advice?': 0.09; 'cursor': 0.09; 'executes': 0.09; 'integer,': 0.09; 'python:': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'commit': 0.15; "'localhost',": 0.16; '(%s,': 0.16; 'andy': 0.16; 'data)': 0.16; 'main():': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'subject:issue': 0.16; 'wrote:': 0.17; 'thanks,': 0.18; 'jan': 0.18; 'all,': 0.21; 'trying': 0.21; 'import': 0.21; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'host': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'values': 0.26; 'skip:# 10': 0.27; 'key,': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'call.': 0.30; 'figure': 0.30; 'primary': 0.30; 'up.': 0.31; 'code': 0.31; 'anyone': 0.33; 'table': 0.35; 'something': 0.35; 'created': 0.36; 'but': 0.36; 'test': 0.36; 'enough': 0.36; 'data': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'received:192': 0.39; 'received:192.168': 0.40; 'most': 0.61; 'email addr:gmail.com': 0.63; 'offer': 0.65; 'serial': 0.66; 'today': 0.67; 'below.': 0.68; '(id': 0.84; '2013': 0.84; 'working,': 0.84; 'preventing': 0.91 Date: Sun, 06 Jan 2013 16:44:47 -0500 From: Mitya Sirenef User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1 MIME-Version: 1.0 To: andydtaylor@gmail.com Subject: Re: psycopg2 cursor.execute CREATE TABLE issue References: <185b6d9e-99ce-4f2a-81ea-d9a63b81b4cf@googlegroups.com> In-Reply-To: <185b6d9e-99ce-4f2a-81ea-d9a63b81b4cf@googlegroups.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1357508694 news.xs4all.nl 6844 [2001:888:2000:d::a6]:39883 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36288 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/