postgresqlplpgsqlpostgresql-8.3

How to create a function in postgresql that accepts array of parameters and returns a table


Here is how my function is looks:

create or replace function datafabric.test(psi_codes text[])
returns table (asset character varying (255), parent_asset character varying (255))
as
$$
select asset, parent_asset 
from americas.asset a
left join americas.prod_int p on a.row_id = p.row_id
where root_asset_id in (select root_asset_id from americas.asset where p.name =  ANY($1))
$$ LANGUAGE 'SQL' VOLATILE;

However, the problem is that I am getting this

ERROR: function datafabric.test() does not exist SQL state: 42883 DURING the CREATION OF THE FUNCTION.

Please note that this function works. However, I want to output the results on pgadmin screen. I am not able to do that now.

Please help. I am using postgresql 8.3 version.


Solution

  • PostgreSQL 8.3 doesn't support RETURNS TABLE for functions. You also have to specify the language of a function without the quotes.

    You can achieve a similar behaviour through the following:

    create or replace function 
           datafabric.test(psi_codes text[],
                           OUT asset character varying (255),
                           OUT parent_asset character varying (255))
           RETURNS SETOF RECORD as $$
    select asset, parent_asset 
    from americas.asset a
    left join americas.prod_int p on a.row_id = p.row_id
    where root_asset_id in (select root_asset_id from americas.asset where p.name =  ANY($1))
    $$ LANGUAGE SQL VOLATILE;