Thread: [GENERAL] libpq confusion

[GENERAL] libpq confusion

From
Igor Korot
Date:
Hi, ALL,

draft=# SELECT 1 FROM abcattbl WHERE abt_tnam = 'leagues';?column?
----------
(0 rows)


However running it thru the PQexecParam() I am getting "PGRES_TUPLES_OK"
which means that the such record exist.

How do I properly check if the record exists from libpq?


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Re: [GENERAL] libpq confusion

From
Pavel Stehule
Date:


2017-09-20 5:36 GMT+02:00 Igor Korot <ikorot01@gmail.com>:
Hi, ALL,

draft=# SELECT 1 FROM abcattbl WHERE abt_tnam = 'leagues';
 ?column?
----------
(0 rows)


However running it thru the PQexecParam() I am getting "PGRES_TUPLES_OK"
which means that the such record exist.

That means so this command doesn't fail  - not so there  are some record.

you can use different query, that returns true, false

SELECT EXISTS(SELECT * FROM abcattbl WHERE abt_tnam = 'leagues');

Regards

Pavel


How do I properly check if the record exists from libpq?


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Re: [GENERAL] libpq confusion

From
Allan Harvey
Date:
>How do I properly check if the record exists from libpq?

Igor,
I use PQntuples() to check the number of ... tuples, for > 0

Allan

______________________________________________________________________
This e-mail message may contain confidential or legally privileged information and is only for the use of the intended
recipient(s).Any unauthorized disclosure, dissemination, distribution, copying or the taking of any action in reliance
onthe information herein is prohibited. E-mails are not secure and cannot be guaranteed to be error free as they can be
intercepted,amended, or contain viruses. Anyone who communicates with us by e-mail is deemed to have accepted these
risks.GFG Alliance Australia and its related bodies corporate and the sender are not responsible for errors or
omissionsin this message and deny any responsibility for any damage arising from the use of this e-mail. Any opinion
andother statement contained in this message and any attachment are solely those of the author and do not necessarily
representthose of the company. All and any rights as to confidentiality, legal professional privilege and copyright are
expresslyreserved. 

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Re: [GENERAL] libpq confusion

From
Igor Korot
Date:
Hi, guys,

On Wed, Sep 20, 2017 at 12:20 AM, Allan Harvey
<allan.harvey@libertyonesteel.com> wrote:
>
>>How do I properly check if the record exists from libpq?
>
> Igor,
> I use PQntuples() to check the number of ... tuples, for > 0

I was actually curious - isn't it what "PGRES_COMMAND_OK" for?
IIUC, this constant indicates successful query run, but no records was
generated.

Or am I missing something and I will have to check PQntuples()?

Thank you.

>
> Allan
>
> ______________________________________________________________________
> This e-mail message may contain confidential or legally privileged information and is only for the use of the
intendedrecipient(s). Any unauthorized disclosure, dissemination, distribution, copying or the taking of any action in
relianceon the information herein is prohibited. E-mails are not secure and cannot be guaranteed to be error free as
theycan be intercepted, amended, or contain viruses. Anyone who communicates with us by e-mail is deemed to have
acceptedthese risks. GFG Alliance Australia and its related bodies corporate and the sender are not responsible for
errorsor omissions in this message and deny any responsibility for any damage arising from the use of this e-mail. Any
opinionand other statement contained in this message and any attachment are solely those of the author and do not
necessarilyrepresent those of the company. All and any rights as to confidentiality, legal professional privilege and
copyrightare expressly reserved. 


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Re: [GENERAL] libpq confusion

From
John R Pierce
Date:
On 9/20/2017 6:30 AM, Igor Korot wrote:
Hi, guys,

On Wed, Sep 20, 2017 at 12:20 AM, Allan Harvey
<allan.harvey@libertyonesteel.com> wrote:
How do I properly check if the record exists from libpq?
Igor,
I use PQntuples() to check the number of ... tuples, for > 0
I was actually curious - isn't it what "PGRES_COMMAND_OK" for?
IIUC, this constant indicates successful query run, but no records was
generated.

Or am I missing something and I will have to check PQntuples()?


a query that returns zero rows is still successful.

-- 
john r pierce, recycling bits in santa cruz

Re: [GENERAL] libpq confusion

From
Igor Korot
Date:
Hi, John,

On Wed, Sep 20, 2017 at 12:02 PM, John R Pierce <pierce@hogranch.com> wrote:
> On 9/20/2017 6:30 AM, Igor Korot wrote:
>
> Hi, guys,
>
> On Wed, Sep 20, 2017 at 12:20 AM, Allan Harvey
> <allan.harvey@libertyonesteel.com> wrote:
>
> How do I properly check if the record exists from libpq?
>
> Igor,
> I use PQntuples() to check the number of ... tuples, for > 0
>
> I was actually curious - isn't it what "PGRES_COMMAND_OK" for?
> IIUC, this constant indicates successful query run, but no records was
> generated.
>
> Or am I missing something and I will have to check PQntuples()?
>
>
> a query that returns zero rows is still successful.

From the documentation:
https://www.postgresql.org/docs/9.1/static/libpq-exec.html

[quote]
PGRES_COMMAND_OK

Successful completion of a command returning no data.
[/quote]

No data = no rows, right?

Thank you.


>
> --
> john r pierce, recycling bits in santa cruz


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Re: [GENERAL] libpq confusion

From
John R Pierce
Date:
On 9/20/2017 10:34 AM, Igor Korot wrote:
>From the documentation:
https://www.postgresql.org/docs/9.1/static/libpq-exec.html

[quote]
PGRES_COMMAND_OK

Successful completion of a command returning no data.
[/quote]

No data = no rows, right?

from that same page, a bit farther down, clarifying the potentially confusing wording.

If the result status is PGRES_TUPLES_OK, then the functions described below can be used to retrieve the rows returned by the query. Note that a SELECT command that happens to retrieve zero rows still shows PGRES_TUPLES_OK. PGRES_COMMAND_OK is for commands that can never return rows (INSERT, UPDATE, etc.). A response of PGRES_EMPTY_QUERY might indicate a bug in the client software.


-- 
john r pierce, recycling bits in santa cruz

Re: [GENERAL] libpq confusion

From
Igor Korot
Date:
Thx.
So it is referring to the command not a "command returning no data". ;-)

On Wed, Sep 20, 2017 at 1:42 PM, John R Pierce <pierce@hogranch.com> wrote:
> On 9/20/2017 10:34 AM, Igor Korot wrote:
>
> >From the documentation:
> https://www.postgresql.org/docs/9.1/static/libpq-exec.html
>
> [quote]
> PGRES_COMMAND_OK
>
> Successful completion of a command returning no data.
> [/quote]
>
> No data = no rows, right?
>
> from that same page, a bit farther down, clarifying the potentially
> confusing wording.
>
> If the result status is PGRES_TUPLES_OK, then the functions described below
> can be used to retrieve the rows returned by the query. Note that a SELECT
> command that happens to retrieve zero rows still shows PGRES_TUPLES_OK.
> PGRES_COMMAND_OK is for commands that can never return rows (INSERT, UPDATE,
> etc.). A response of PGRES_EMPTY_QUERY might indicate a bug in the client
> software.
>
>
> --
> john r pierce, recycling bits in santa cruz


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Re: [GENERAL] libpq confusion

From
Thomas Delrue
Date:
On Wednesday, September 20, 2017 1:47:05 PM EDT Igor Korot wrote:
>Thx.
>So it is referring to the command not a "command returning no data". ;-)

assumingcreate table t (c int);

select c from t;- PQresultStatus(result) == PGRES_TUPLES_OK- PQntuples(result) == number or rows returned (int)
insert into t(c)values(1);- PQresultStatus(result) ==PGRES_COMMAND_OK- PQcmdTuples(result) == "1" (note: char*)
insert into t(c)values(1) returning c;- PQresultStatus(result) ==PGRES_TUPLES_OK- PQntuples(result) == 1 (int)

>On Wed, Sep 20, 2017 at 1:42 PM, John R Pierce <pierce@hogranch.com> wrote:
>> On 9/20/2017 10:34 AM, Igor Korot wrote:
>> >From the documentation:
>> https://www.postgresql.org/docs/9.1/static/libpq-exec.html
>> 
>> [quote]
>> PGRES_COMMAND_OK
>> 
>> Successful completion of a command returning no data.
>> [/quote]
>> 
>> No data = no rows, right?
>> 
>> from that same page, a bit farther down, clarifying the potentially
>> confusing wording.
>> 
>> If the result status is PGRES_TUPLES_OK, then the functions described below
>> can be used to retrieve the rows returned by the query. Note that a SELECT
>> command that happens to retrieve zero rows still shows PGRES_TUPLES_OK.
>> PGRES_COMMAND_OK is for commands that can never return rows (INSERT,
>> UPDATE,
>> etc.). A response of PGRES_EMPTY_QUERY might indicate a bug in the client
>> software.