Thread: is it possibile get the psql prompt output?

is it possibile get the psql prompt output?

From
Ottavio Campana
Date:
I am writing a small python script and I'd like to get the output I
would get as if I executed the commands from psql. Let's make an
example, suppose you have a small table such as

create table xxx_test (
         id serial,
         description text);

and that you perform this command in psql

mydb=# INSERT INTO xxx_test values (default, 'ciao');
INSERT 0 1
mydb=#

In python I do

cursor = connection.cursor ()
cursor.execute (command)
connection.commit ()

with command being the insert command. Now the question is: is there a
way to get the "INSERT 01" back?

Thank you,

Ottavio

Re: is it possibile get the psql prompt output?

From
Federico Di Gregorio
Date:
On 16/05/12 09:06, Ottavio Campana wrote:
> I am writing a small python script and I'd like to get the output I
> would get as if I executed the commands from psql. Let's make an
> example, suppose you have a small table such as
>
> create table xxx_test (
>         id serial,
>         description text);
>
> and that you perform this command in psql
>
> mydb=# INSERT INTO xxx_test values (default, 'ciao');
> INSERT 0 1
> mydb=#
>
> In python I do
>
> cursor = connection.cursor ()
> cursor.execute (command)
> connection.commit ()
>
> with command being the insert command. Now the question is: is there a
> way to get the "INSERT 01" back?

You can't because that's generated by psql on the client and it isn't
from the server. You can get the number of affected rows from the
cursor, after the .execute().

federico

--
Federico Di Gregorio                         federico.digregorio@dndg.it
Studio Associato Di Nunzio e Di Gregorio                  http://dndg.it
 In science one tries to tell people, in such a way as to be understood
  by everyone, something that no one ever knew before. But in poetry,
  it's the exact opposite.                                 -- Paul Dirac

Re: is it possibile get the psql prompt output?

From
Egbert Bouwman
Date:
On Wed, 16 May 2012 09:06:56 +0200
Ottavio Campana <ottavio@campana.vi.it> wrote:

>
> and that you perform this command in psql
>
> mydb=# INSERT INTO xxx_test values (default, 'ciao');
> INSERT 0 1
> mydb=#
>
> In python I do
>
> cursor = connection.cursor ()
> cursor.execute (command)
> connection.commit ()
>
> with command being the insert command. Now the question is: is there
> a way to get the "INSERT 01" back?
>

Is this what you are looking for :
cursor.execute(command)
cursor.statusmessage


e

--
Egbert Bouwman