PREPARE vs query with MULTIPLE statements

Started by Andrei Kovalevskiabout 18 years ago3 messages
#1Andrei Kovalevski
andyk@commandprompt.com
4 attachment(s)

Hello.

I have found an interesting FRONTEND/BACKEND protocol behaviour. Let's
consider following query:
"SELECT 1; SELECT 2; SELECT3; SELECT4;"

1) If I send it as a simple query - I'm getting:
- correct results for SELECT 1; SELECT 2; SELECT3; SELECT4;
- and then one ReadyForQuery response
from backend.
[send_simple.log & recv_simple.log]

2) If I send it as 'PREPARE "SQL_CUR1" AS SELECT 1; SELECT 2; SELECT3;
SELECT4;' and then 'EXECUTE "SQL_CUR1" - I'm getting:
- results for SELECT 1; SELECT2; SELECT 3;
- ReadyForQuery response
- results for SELECT 4;
- one more ReadyForQuery response
from backend
[send_prepared.log & recv_prepared.log]

Is this behavour is correct and expected?

P.s. Tested on Windows with PostgreSQL 8.0, 8.1 and 8.2 with the same
results.

Thank You,
Andrei.

Attachments:

recv_prepare.logtext/plain; name=recv_prepare.logDownload
recv_simple.logtext/plain; name=recv_simple.logDownload
send_prepare.logtext/plain; name=send_prepare.logDownload
#userandreidatabasetestp(md5********************************Q%SET client_encoding to 'UNICODE'QSELECT version()Q=PREPARE"SQL_CUR1"AS SELECT 1;SELECT 2;SELECT 3;SELECT 4;QEXECUTE"SQL_CUR1"
send_simple.logtext/plain; name=send_simple.logDownload
#userandreidatabasetestp(md5********************************Q%SET client_encoding to 'UNICODE'QSELECT version()Q)SELECT 1;SELECT 2;SELECT 3;SELECT 4;
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrei Kovalevski (#1)
Re: PREPARE vs query with MULTIPLE statements

Andrei Kovalevski <andyk@commandprompt.com> writes:

2) If I send it as 'PREPARE "SQL_CUR1" AS SELECT 1; SELECT 2; SELECT3;
SELECT4;' and then 'EXECUTE "SQL_CUR1" - I'm getting:
- results for SELECT 1; SELECT2; SELECT 3;
- ReadyForQuery response
- results for SELECT 4;
- one more ReadyForQuery response
from backend

Is this behavour is correct and expected?

You seem to have some odd ideas about what the semicolons mean.
The prepare command there is PREPARE "SQL_CUR1" AS SELECT 1
... no more and no less.

regards, tom lane

#3Andrei Kovalevski
andyk@commandprompt.com
In reply to: Tom Lane (#2)
Re: PREPARE vs query with MULTIPLE statements

Yes, Thank you!

Tom Lane wrote:

Show quoted text

Andrei Kovalevski <andyk@commandprompt.com> writes:

2) If I send it as 'PREPARE "SQL_CUR1" AS SELECT 1; SELECT 2; SELECT3;
SELECT4;' and then 'EXECUTE "SQL_CUR1" - I'm getting:
- results for SELECT 1; SELECT2; SELECT 3;
- ReadyForQuery response
- results for SELECT 4;
- one more ReadyForQuery response
from backend

Is this behavour is correct and expected?

You seem to have some odd ideas about what the semicolons mean.
The prepare command there is PREPARE "SQL_CUR1" AS SELECT 1
... no more and no less.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq