Re: [GENERAL] libpq confusion

2017-09-22 Thread Thomas Delrue
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". ;-)

assuming
create 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  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.


signature.asc
Description: This is a digitally signed message part.


Re: [GENERAL] libpq confusion

2017-09-20 Thread Igor Korot
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  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

2017-09-20 Thread John R Pierce

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 isPGRES_TUPLES_OK, then the functions described
   below can be used to retrieve the rows returned by the query. Note
   that aSELECTcommand that happens to retrieve zero rows still
   showsPGRES_TUPLES_OK.PGRES_COMMAND_OKis for commands that can never
   return rows (INSERT,UPDATE, etc.). A response
   ofPGRES_EMPTY_QUERYmight indicate a bug in the client software.


--
john r pierce, recycling bits in santa cruz



Re: [GENERAL] libpq confusion

2017-09-20 Thread Igor Korot
Hi, John,

On Wed, Sep 20, 2017 at 12:02 PM, John R Pierce  wrote:
> On 9/20/2017 6:30 AM, Igor Korot wrote:
>
> Hi, guys,
>
> On Wed, Sep 20, 2017 at 12:20 AM, Allan Harvey
>  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

2017-09-20 Thread John R Pierce

On 9/20/2017 6:30 AM, Igor Korot wrote:

Hi, guys,

On Wed, Sep 20, 2017 at 12:20 AM, Allan Harvey
  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

2017-09-20 Thread Allan Harvey

>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 on the 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 omissions in this message and 
deny any responsibility for any damage arising from the use of this e-mail. Any 
opinion and other statement contained in this message and any attachment are 
solely those of the author and do not necessarily represent those of the 
company. All and any rights as to confidentiality, legal professional privilege 
and copyright are 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

2017-09-20 Thread Igor Korot
Hi, guys,

On Wed, Sep 20, 2017 at 12:20 AM, Allan Harvey
 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 intended recipient(s). Any 
> unauthorized disclosure, dissemination, distribution, copying or the taking 
> of any action in reliance on the 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 
> omissions in this message and deny any responsibility for any damage arising 
> from the use of this e-mail. Any opinion and other statement contained in 
> this message and any attachment are solely those of the author and do not 
> necessarily represent those of the company. All and any rights as to 
> confidentiality, legal professional privilege and copyright are 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

2017-09-19 Thread Pavel Stehule
2017-09-20 5:36 GMT+02:00 Igor Korot :

> 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
>