pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: depstein@alliedtesting.com
To: pgsql-bugs@postgresql.org
Cc: pgagarinov@alliedtesting.com
Cc: vshahov@alliedtesting.com
Subject: Re: Can't use WITH in a PERFORM query in PL/pgSQL?
Date: Thu, 24 Mar 2011 18:21:36 +0300
Message-ID: <29F36C7C98AB09499B1A209D48EAA615B501DA9401@mail2a.alliedtesting.com> (raw)

Update: It has been suggested to wrap perform around a select like this:

do
$$begin
perform(
with A as (select 1 as foo)
select foo from A
);
end$$;

This won't work if select returns more than one statement:

do
$$begin
perform(
with A as (select generate_series(1,3) as foo)
select foo from A
);
end$$;

   ERROR:  more than one row returned by a subquery used as an expression

So I still say it's broken.

(Sorry for top-posting: I am forced to use Outlook at work...)

From: Dmitry Epstein
Sent: Sunday, March 06, 2011 4:29 PM
To: 'pgsql-bugs@postgresql.org'
Cc: Peter Gagarinov; Vladimir Shahov
Subject: Can't use WITH in a PERFORM query in PL/pgSQL?

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

www.alliedtesting.com<http://www.alliedtesting.com/;
We Deliver Quality.

view thread (24+ messages)  latest in thread

Message-ID: <29F36C7C98AB09499B1A209D48EAA615B501DA9401@mail2a.alliedtesting.com>
Permalink:  ../29F36C7C98AB09499B1A209D48EAA615B501DA9401@mail2a.alliedtesting.com/
Also on:    postgresql.org/message-id/29F36C7C98AB09499B1A209D48EAA615B501DA9401@mail2a.alliedtesting.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: depstein@alliedtesting.com, pgagarinov@alliedtesting.com, vshahov@alliedtesting.com
  Subject: Re: Can't use WITH in a PERFORM query in PL/pgSQL?
  In-Reply-To: <29F36C7C98AB09499B1A209D48EAA615B501DA9401@mail2a.alliedtesting.com>
  References: <29F36C7C98AB09499B1A209D48EAA615B501DA9401@mail2a.alliedtesting.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox