Skip site navigation (1) Skip section navigation (2)

Re: Fetching query result problem

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Jacek Kałucki <laborm(at)rz(dot)onet(dot)pl>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: Fetching query result problem
Date: 2012-01-16 13:18:30
Message-ID: CA+mi_8aUEV7yVXr05V9iTtAEYuWzHtnZ7RScgQwB_fn6cNUc3w@mail.gmail.com (view raw or flat)
Thread:
Lists: psycopg
2012/1/16 Jacek Kałucki <laborm(at)rz(dot)onet(dot)pl>:
> Hi.
>
> I have a problem with some query.
> When I issue it from within postgresql console, it returns correct rows
> count as a result,
> but when executed within psycopg2 cursor.execute() row count differs.
> In first situation I get 5 rows versus 3 at second time.
[...]
> Could you give me any suggestions how to figure the reason out?

There's no reason why this should happen.

- It could be a different in transactions usage: a query run in psql
is not wrapped in a transaction whereas psycopg has an implicit
"begin" before, and data is not committed until you explicitly commit:
make sure the data you are expecting is visible. Try running the query
in psycopg with autocommit = true to get the same data visibility you
have in psql.

- could you have python data types converted to something unexpected?
Enable server logging to see the query the backend receives, and use
diff to compare the logs and spot differences between what received
from psql and what from psycopg.

- check the connection string: you may be talking to the wrong database.

-- Daniele

In response to

Responses

psycopg by date

Next:From: Jacek KałuckiDate: 2012-01-16 13:53:37
Subject: Re: Fetching query result problem
Previous:From: Jacek KałuckiDate: 2012-01-16 12:53:20
Subject: Fetching query result problem

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group