Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id D21E31337B8B for ; Sun, 6 Mar 2011 09:36:12 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 49377-08 for ; Sun, 6 Mar 2011 13:36:05 +0000 (UTC) X-Greylist: delayed 00:05:27.14098 by SQLgrey-1.7.6 Received: from mail2a.alliedtesting.com (unknown [80.249.134.186]) by mail.postgresql.org (Postfix) with ESMTP id 589FC1337B3E for ; Sun, 6 Mar 2011 09:36:04 -0400 (AST) Received: from mail2a.alliedtesting.com ([192.168.66.21]) by mail2a.alliedtesting.com ([192.168.66.21]) with mapi; Sun, 6 Mar 2011 16:29:30 +0300 From: To: CC: , Date: Sun, 6 Mar 2011 16:29:28 +0300 Subject: Can't use WITH in a PERFORM query in PL/pgSQL? Thread-Topic: Can't use WITH in a PERFORM query in PL/pgSQL? Thread-Index: AcvcAnXGltCtVyYLSZay5+9Rf37ARA== Message-ID: <29F36C7C98AB09499B1A209D48EAA615B501DA902C@mail2a.alliedtesting.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: multipart/alternative; boundary="_000_29F36C7C98AB09499B1A209D48EAA615B501DA902Cmail2aalliedt_" MIME-Version: 1.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.106 tagged_above=-5 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001, RDNS_NONE=0.793 X-Spam-Level: X-Archive-Number: 201103/122 X-Sequence-Number: 29632 --_000_29F36C7C98AB09499B1A209D48EAA615B501DA902Cmail2aalliedt_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable PostgreSQL 9.0.1 It seems that PostgreSQL doesn't understand the WITH construct when used in= a PERFORM query inside PL/pgSQL functions and code blocks: Example: do $$begin with A as (select 1 as foo) perform foo from A; end$$; syntax error at or near "perform" do $$begin with A as (select 1 as foo) select foo from A; end$$; query has no destination for result data The only workaround that I can think of is to use a dummy variable to captu= re the query result. This has to be done even when the query doesn't have a= result (as when calling a function returning void). do $$declare dummy record; begin with A as (select 1 as foo) select foo into dummy from A; end$$; Dmitry Epstein | Developer Allied Testing T + 7 495 544 48 69 Ext 417 M + 7 926 215 73 36 www.alliedtesting.com We Deliver Quality. --_000_29F36C7C98AB09499B1A209D48EAA615B501DA902Cmail2aalliedt_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

PostgreSQL 9.0.1=

 

It seems that PostgreSQL doesn’t understand the WITH construct whe= n used in a PERFORM query inside PL/pgSQL functions and code blocks:

 

Exam= ple:

 

do

$$begin

with A as (select 1 as foo)

perform foo from A;

end$$;

 

 &nbs= p;  syntax error at or near "perform"

 

do

$$begin

with A as (sel= ect 1 as foo)

select foo from A;

end$$;

=  

    query has no destin= ation for result data

 <= /p>

The only workaround that I can think of is to use a= dummy variable to capture the query result. This has to be done even when = the query doesn’t have a result (as when calling a function returning= void).

 

do

$$declare

dummy record;

begin

with A as (select 1 as foo)

=

select foo into dummy from A;

end$$;

 

 

Dmitry Epstein= | Developer

Allied Testing=

T + 7 495 544 48 69 Ext 417

M= + 7 926 215 73 36

 

<= a href=3D"http://www.alliedtesting.com/">www.= alliedtesting.com<= /span>

We Deliver Quality.

&= nbsp;

= --_000_29F36C7C98AB09499B1A209D48EAA615B501DA902Cmail2aalliedt_--