Re: PL/pgSQL PERFORM with CTE

From: "David E(dot) Wheeler" <david(at)justatheory(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: 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 13:32:11
Message-ID: 797AA542-315F-426A-BBE2-D8506F002B8C@justatheory.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Aug 20, 2013, at 3:18 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:

> can you show some examples, please

This is not dissimilar to what I am actually doing:

CREATE TABLE foo (id SERIAL PRIMARY KEY, name TEXT);

CREATE OR REPLACE FUNCTION shipit (
VARIADIC things TEXT[]
) RETURNS BOOL LANGUAGE plpgsql AS $$
BEGIN
WITH inserted AS (
INSERT INTO foo (name)
SELECT * FROM unnest(things)
RETURNING id
)
PERFORM pg_notify(
'inserted ids',
ARRAY(SELECT * FROM inserted)::text
);
RETURN FOUND;
END;
$$;

Only I am using a dummy row variable instead of PERFORM, of course.

Best,

David

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Boszormenyi Zoltan 2013-08-20 13:37:17 Re: GSOC13 proposal - extend RETURNING syntax
Previous Message Stephen Frost 2013-08-20 13:25:14 Re: ALTER SYSTEM SET command to change postgresql.conf parameters (RE: Proposal for Allow postgresql.conf values to be changed via SQL [review])