Re: DELETE...RETURNING problem with libpq

From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: Brice André <brice(at)famille-andre(dot)be>
Cc: Wolfe Whalen <wolfe(at)quios(dot)net>, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: DELETE...RETURNING problem with libpq
Date: 2013-05-26 06:51:19
Message-ID: 1369551079.3087.4.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sat, 2013-05-25 at 14:49 +0200, Brice André wrote:
> Hi Wolfe,
>
> First, thanks for your help.
>
> I tried your code, but it does not work... the function returns a string :
> "0". When I check, this command properly modifies one row, as expected.
>

It works for me with PQntuples.

> I don't know if it may help, but just in case... The DELETE operation is
> not performed on a table : it is performed on a view. I have a rule on that
> view that, instead of performing a delete on the corresponding table,
> performs an update with table entry tagged as deleted (in a dedicated
> column of the table). This code (sql part) works for years and, when
> executing this command by other ways (php and pgadmin), it deletes and
> returns expected data. With libpq, it deletes, but does not return anything.
>

You'll find my test case attached. It's C code, not C++, but I guess it
won't be a big issue :)

It gives me this result:

$ ./example
connection OK
prepare OK
execute OK
ntuples: 81
cleanup OK

81 is the number of lines to delete. If I launch it another time, it
gives me 0 as all the rows have already been deleted.

Hope it helps.

--
Guillaume
http://blog.guillaume.lelarge.info
http://www.dalibo.com

Attachment Content-Type Size
example.tgz application/x-compressed-tar 1.3 KB

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Brice André 2013-05-26 18:35:15 Re: DELETE...RETURNING problem with libpq
Previous Message Marc Mamin 2013-05-25 17:52:23 Re: Advice on re-writing a SELECT query.