Search Postgresql Archives

Ad hoc SETOF type definition?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Pg 9.6.24 (Yes, I know it's EOL.)

This simple "programming example" function works perfectly. However, it requires me to create the TYPE "foo".

CREATE TYPE foo AS (tab_name TEXT, num_pages INT);
CREATE FUNCTION dba.blarge()
    RETURNS SETOF foo
    LANGUAGE plpgsql
    AS
$$
    DECLARE
        ret foo;
        bar CURSOR FOR
            select relname::text as table_name, relpages
            from pg_class where relkind = 'r'
            order by 1;
    BEGIN
        FOR i IN bar LOOP
            SELECT i.table_name, i.relpages INTO ret;
            RETURN NEXT ret;
        END LOOP;
    END;
$$;

Is there a way to define the SETOF record on the fly, like you do with RETURNS TABLE (f1 type1, f2 type2)?

--
Born in Arizona, moved to Babylonia.





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux