Re: PL/pgSQL PERFORM with CTE

From: Boszormenyi Zoltan <zb(at)cybertec(dot)at>
To: "David E(dot) Wheeler" <david(at)justatheory(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Marko Tiikkaja <marko(at)joh(dot)to>, pgsql-hackers Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PL/pgSQL PERFORM with CTE
Date: 2013-08-20 12:46:15
Message-ID: 52136517.4040702@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2013-08-20 14:35 keltezéssel, David E. Wheeler írta:
> On Aug 20, 2013, at 2:31 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
>> but it works
>>
>> postgres=# do $$begin with x as (select 10) insert into omega select * from x; end;$$;
>> DO
> But this does not:
>
> david=# DO $$
> david$# BEGIN
> david$# PERFORM * FROM (
> david$# WITH inserted AS (
> david$# INSERT INTO foo values (1) RETURNING id
> david$# ) SELECT inserted.id
> david$# ) x;
> david$# END;
> david$# $$;
> ERROR: WITH clause containing a data-modifying statement must be at the top level
> LINE 2: WITH inserted AS (
> ^
> QUERY: SELECT * FROM (
> WITH inserted AS (
> INSERT INTO foo values (1) RETURNING id
> ) SELECT inserted.id
> ) x
> CONTEXT: PL/pgSQL function inline_code_block line 3 at PERFORM

This is the same error as if you put the WITH into a subquery,
which is what PERFORM does.

Proof:

SELECT * FROM (
WITH inserted AS (
INSERT INTO foo values (1) RETURNING id
) SELECT inserted.id
) x;

Best regards,
Zoltán Böszörményi

--
----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
http://www.postgresql.at/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David E. Wheeler 2013-08-20 12:46:44 Re: PL/pgSQL PERFORM with CTE
Previous Message David E. Wheeler 2013-08-20 12:45:25 Re: PL/pgSQL PERFORM with CTE