libpq: multiple commands within single query

Started by Вячеслав Блинниковabout 15 years ago4 messagesgeneral
Jump to latest

By which rules database returns results for multiple commands within single
query?
For example I send (execute) such query (obtain different information about
just connected client):
"SELECT column1 FROM table1; SELECT column2 FROM table2; SELECT column3 FROM
table3;"
And when I get response I expect some results (PGresult structure) for EACH
"SELECT" - so there must be 3 PGresult structures and if one of results
contains zero rows - it means that there are no data (of such type) for such
client yet, but there still can be some data for following "SELECT". For
example (referring to previous example) response can contain 3 results (as I
expect) where first contains 1 row, second 0 rows and third 1 row. So when I
examine the response I can match each PGresult to each "SELECT".
Does it works on this way? Or I missed something?

#2Dmitriy Igrishin
dmitigr@gmail.com
In reply to: Вячеслав Блинников (#1)
Re: libpq: multiple commands within single query

Hey,

18 января 2011 г. 14:24 пользователь Вячеслав Блинников
<slavmfm@gmail.com>написал:

By which rules database returns results for multiple commands within single
query?
For example I send (execute) such query (obtain different information about
just connected client):
"SELECT column1 FROM table1; SELECT column2 FROM table2; SELECT column3
FROM table3;"
And when I get response I expect some results (PGresult structure) for EACH
"SELECT" - so there must be 3 PGresult structures and if one of results
contains zero rows - it means that there are no data (of such type) for such
client yet, but there still can be some data for following "SELECT". For
example (referring to previous example) response can contain 3 results (as I
expect) where first contains 1 row, second 0 rows and third 1 row. So when I
examine the response I can match each PGresult to each "SELECT".
Does it works on this way? Or I missed something?

According the documentation: "the client can be handling the
results of one command while the server is still working on later
queries in the same command string.". The key word here is "later".

--
// Dmitriy.

In reply to: Dmitriy Igrishin (#2)
Re: libpq: multiple commands within single query

Yeah - that is how I do (PGgetResult function returns results until it will
return "NULL" pointer which means that all data for whole "PGsendQuery" was
returned). But what does it mean when query which contain 3 "SELECT"
commands returns just one result (second "PGgetResult()" already returns
null pointer)?

18 января 2011 г. 14:55 пользователь Dmitriy Igrishin
<dmitigr@gmail.com>написал:

Show quoted text

Hey,

18 января 2011 г. 14:24 пользователь Вячеслав Блинников <slavmfm@gmail.com

написал:

By which rules database returns results for multiple commands within single

query?
For example I send (execute) such query (obtain different information
about just connected client):
"SELECT column1 FROM table1; SELECT column2 FROM table2; SELECT column3
FROM table3;"
And when I get response I expect some results (PGresult structure) for
EACH "SELECT" - so there must be 3 PGresult structures and if one of results
contains zero rows - it means that there are no data (of such type) for such
client yet, but there still can be some data for following "SELECT". For
example (referring to previous example) response can contain 3 results (as I
expect) where first contains 1 row, second 0 rows and third 1 row. So when I
examine the response I can match each PGresult to each "SELECT".
Does it works on this way? Or I missed something?

According the documentation: "the client can be handling the
results of one command while the server is still working on later
queries in the same command string.". The key word here is "later".

--
// Dmitriy.

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Вячеслав Блинников (#3)
Re: libpq: multiple commands within single query

=?KOI8-R?B?99HexdPMwdcg4szJzs7Jy8/X?= <slavmfm@gmail.com> writes:

Yeah - that is how I do (PGgetResult function returns results until it will
return "NULL" pointer which means that all data for whole "PGsendQuery" was
returned). But what does it mean when query which contain 3 "SELECT"
commands returns just one result (second "PGgetResult()" already returns
null pointer)?

Most likely, the command failed ... have you tried inspecting the
PGresult to see what status it's reporting?

regards, tom lane