Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39507

Re: psycopg2 craziness

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'log:': 0.04; 'error:': 0.05; 'ignored': 0.05; 'schema': 0.05; 'startup': 0.05; 'python': 0.09; 'exist.': 0.09; 'postgres': 0.09; 'sep': 0.09; 'commit': 0.15; "'localhost',": 0.16; '2.7.3': 0.16; 'complains': 0.16; 'created.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'incomplete': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'shell:': 0.16; 'wrote:': 0.17; 'exists': 0.17; 'trying': 0.21; 'import': 0.21; '"",': 0.22; 'dropped': 0.22; 'exists.': 0.22; 'example': 0.23; 'tables': 0.23; "i've": 0.23; 'connected': 0.24; 'host': 0.24; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'select': 0.26; '(most': 0.27; 'done.': 0.27; "doesn't": 0.28; '>>>>': 0.29; 'issues.': 0.29; "i'm": 0.29; 'maybe': 0.29; 'connections': 0.30; 'primary': 0.30; '(and': 0.32; 'file': 0.32; 'received:84': 0.32; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'skip:- 50': 0.34; 'list': 0.35; 'exist': 0.35; 'sequence': 0.35; 'table': 0.35; 'created': 0.36; 'but': 0.36; 'skip:p 20': 0.36; 'unable': 0.36; 'possible': 0.37; 'execute': 0.37; 'does': 0.37; 'drop': 0.37; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'some': 0.38; 'there,': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'end': 0.40; "you've": 0.61; 'further': 0.61; 'relations': 0.62; 'ever': 0.63; 'email addr:gmail.com': 0.63; 'more': 0.63; 'here': 0.65; 'surprise': 0.65; 'serial': 0.66; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; '(id': 0.84; 'change?': 0.84; 'reply-to:addr:python.org': 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.0 cv=HO4d4PRv c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=_vX2mLoUpDQA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=wVQJY7ok1kQA:10 a=pGLkceISAAAA:8 a=lai_YuCr05rFIcnMP4sA:9 a=wPNLvfGTeEIA:10 a=MSl-tDqOz04A:10 a=mPEqfuHi5cyUD1xo:21 a=0nF1XD0wxitMEM03M9B4ZQ==:117
X-AUTH mrabarnett:2500
Date Fri, 22 Feb 2013 00:36:21 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130215 Thunderbird/17.0.3
MIME-Version 1.0
To python-list@python.org
Subject Re: psycopg2 craziness
References <2427e351-dd19-4e13-af76-d1c41aa5ad3d@googlegroups.com>
In-Reply-To <2427e351-dd19-4e13-af76-d1c41aa5ad3d@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2228.1361493382.2939.python-list@python.org> (permalink)
Lines 162
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1361493382 news.xs4all.nl 6943 [2001:888:2000:d::a6]:41843
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:39507

Show key headers only | View raw


On 2013-02-21 23:27, andydtaylor@gmail.com wrote:
>
>
> Hi,
>
> I'm trying to use psycopg2 but having some issues. Would it be possible to get some pointers? I seem unable to execute any SQL statements.
>
>
> So here are my database tables before (and after) I try to do anything:
>
> postgres=# \c
> You are now connected to database "postgres" as user "postgres".
> postgres=# \d
>                      List of relations
>   Schema |          Name           |   Type   |   Owner
> --------+-------------------------+----------+------------
>   public | loc_all                 | table    | django_dev
>   public | loc_all_unique          | table    | django_dev
>   public | loc_dlr                 | table    | django_dev
>   public | loc_londonbuses         | table    | django_dev
>   public | loc_londonriverservices | table    | django_dev
>   public | loc_londonunderground   | table    | django_dev
>   public | loc_tramlink            | table    | django_dev
>   public | lu_stations_id_seq      | sequence | postgres
>   public | postcode_input          | table    | postgres
>   public | postcode_lat_long       | table    | django_dev
>   public | test_foo                | table    | django_dev
>   public | tubecross               | table    | django_dev
>
>
> Here's what I've been trying to execute in the python shell:
>
>>>> import psycopg2
>>>> import psycopg2.extras
>>>> db = psycopg2.connect(
> ...     host = 'localhost',
> ...     database = 'postgres',
> ...     user = 'postgres',
> ...     password = 'password'
> ...     )
>>>> cursor_to = db.cursor()

You ask it to create a table "foo":

>>>> cursor_to.execute("CREATE TABLE foo (id serial PRIMARY KEY);")

Done. The table "foo" has been created.

You ask it to create a table "foo" again:

>>>> cursor_to.execute("CREATE TABLE foo (id serial PRIMARY KEY);")

It complains because it already exists. No surprise there, you've
already created it.

> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> psycopg2.ProgrammingError: relation "foo" already exists
>
>>>>
>>>>
>>>> cursor_to.execute("CREATE TABLE foo (id serial PRIMARY KEY);")
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> psycopg2.InternalError: current transaction is aborted, commands ignored until end of transaction block
>

Maybe you need to commit the change?

>
> Here's the postgres log:
>
> 2013-02-21 22:22:20 GMT LOG:  database system was shut down at 2013-02-21 22:21:41 GMT
> 2013-02-21 22:22:20 GMT LOG:  autovacuum launcher started
> 2013-02-21 22:22:20 GMT LOG:  database system is ready to accept connections
> 2013-02-21 22:22:20 GMT LOG:  incomplete startup packet
> 2013-02-21 22:22:21 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 22:22:22 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 22:22:22 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 22:22:23 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 22:22:23 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 22:22:24 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 22:22:24 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 22:22:25 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 22:22:25 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 22:22:26 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 22:22:26 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 22:22:26 GMT LOG:  incomplete startup packet
> 2013-02-21 22:28:52 GMT ERROR:  relation "foo" already exists
> 2013-02-21 22:28:52 GMT STATEMENT:  CREATE TABLE foo (id serial PRIMARY KEY);
> 2013-02-21 22:34:53 GMT ERROR:  current transaction is aborted, commands ignored until end of transaction block
> 2013-02-21 22:34:53 GMT STATEMENT:  CREATE TABLE foo (id serial PRIMARY KEY);
>
>
>
>
> Further example from python shell:
>
> andyt@andyt-ThinkPad-X61:~$ python
> Python 2.7.3 (default, Sep 26 2012, 21:51:14)
> [GCC 4.7.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import psycopg2
>>>> import psycopg2.extras
>>>> db = psycopg2.connect(
> ...     host = 'localhost',
> ...     database = 'postgres',
> ...     user = 'postgres',
> ...     password = 'password'
> ...     )
>>>> cursor_to = db.cursor()

You ask it to drop the table "tubecross" if it exists.

>>>> cursor_to.execute("DROP TABLE IF EXISTS tubecross")

Done. The table "done", if it ever existed, has been dropped.

You ask it to drop the table "tubecross" again.

>>>> cursor_to.execute("DROP TABLE tubecross")

It complains because it doesn't exist. No surprise there, you've
already dropped it.

> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> psycopg2.ProgrammingError: table "tubecross" does not exist
>
>>>> cursor_to.execute("SELECT * FROM loc_tramlink")
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> psycopg2.InternalError: current transaction is aborted, commands ignored until end of transaction block
>

Maybe you need to commit the change?

>
> Postgres log:
>
> 2013-02-21 23:08:18 GMT LOG:  database system was shut down at 2013-02-21 23:07:40 GMT
> 2013-02-21 23:08:18 GMT LOG:  autovacuum launcher started
> 2013-02-21 23:08:18 GMT LOG:  database system is ready to accept connections
> 2013-02-21 23:08:18 GMT LOG:  incomplete startup packet
> 2013-02-21 23:08:19 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 23:08:19 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 23:08:20 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 23:08:20 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 23:08:21 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 23:08:21 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 23:08:22 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 23:08:22 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 23:08:23 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 23:08:23 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 23:08:24 GMT FATAL:  password authentication failed for user "postgres"
> 2013-02-21 23:08:24 GMT LOG:  incomplete startup packet
> 2013-02-21 23:19:23 GMT ERROR:  table "tubecross" does not exist
> 2013-02-21 23:19:23 GMT STATEMENT:  DROP TABLE tubecross
> 2013-02-21 23:22:05 GMT ERROR:  current transaction is aborted, commands ignored until end of transaction block
> 2013-02-21 23:22:05 GMT STATEMENT:  SELECT * FROM loc_tramlink
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

psycopg2 craziness andydtaylor@gmail.com - 2013-02-21 15:27 -0800
  Re: psycopg2 craziness MRAB <python@mrabarnett.plus.com> - 2013-02-22 00:36 +0000
    Re: psycopg2 craziness andydtaylor@gmail.com - 2013-02-21 16:44 -0800
    Re: psycopg2 craziness andydtaylor@gmail.com - 2013-02-21 16:44 -0800
  Re: psycopg2 craziness Chris Angelico <rosuav@gmail.com> - 2013-02-22 17:22 +1100

csiph-web