Re: PL/pgSQL PERFORM with CTE - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: PL/pgSQL PERFORM with CTE
Date
Msg-id CAFj8pRAzzNYxLE8hj3-UHzChu5CX_9fM_hdM=aObMDSs0N2Epw@mail.gmail.com
Whole thread Raw
In response to Re: PL/pgSQL PERFORM with CTE  ("David E. Wheeler" <david@justatheory.com>)
Responses Re: PL/pgSQL PERFORM with CTE
List pgsql-hackers



2013/8/20 David E. Wheeler <david@justatheory.com>
On Aug 20, 2013, at 3:18 PM, Pavel Stehule <pavel.stehule@gmail.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.

pg_notify returns void, so there are no necessary casting to void

so enhanced check - so all returned columns are void should be enough

Regards

Pavel
 

Best,

David


pgsql-hackers by date:

Previous
From: Boszormenyi Zoltan
Date:
Subject: Re: GSOC13 proposal - extend RETURNING syntax
Next
From: Andrew Dunstan
Date:
Subject: Re: Fix Windows socket error checking for MinGW