Re: PL/pgSQL PERFORM with CTE
От | Pavel Stehule |
---|---|
Тема | Re: PL/pgSQL PERFORM with CTE |
Дата | |
Msg-id | CAFj8pRA6sSXjJRk5cj6GMPJH1ExEfKcujc1e_C4UFsHM6eMAbA@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: PL/pgSQL PERFORM with CTE ("David E. Wheeler" <david@justatheory.com>) |
Ответы |
Re: PL/pgSQL PERFORM with CTE
|
Список | pgsql-hackers |
2013/8/20 David E. Wheeler <david@justatheory.com>
On Aug 20, 2013, at 2:31 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:But this does not:
> but it works
>
> postgres=# do $$begin with x as (select 10) insert into omega select * from x; end;$$;
> DOdavid$# PERFORM * FROM (
david=# DO $$
david$# BEGIN
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
yes, in this context you should not use a PERFORM
PL/pgSQL protect you before useless queries - so you can use a CTE without returned result directly or CTE with result via PERFORM statement (and in this case it must be unmodifing CTE).
Sorry, I don't see any problem - why you return some from CTE and then you throw this result?
Best,
David
В списке pgsql-hackers по дате отправления: