I'm running PostgreSQL and NodeJS.
In PostgreSQL I have a custom function dummy:
... RETURNS RECORD AS $$
...
DECLARE ret RECORD
...
RETURN ret;
END;
$$ LANGUAGE plpgsql;
In NodeJS this returns a tuple, as a string:
(x,y,z)
So I have to manually split the string and read the parts...
Is it possible to have PostgreSQL return the tuple as a rowor similar, so I can use data.x, data.y and data.zin NodeJS instead?
fn():
t=# create or replace function f() returns record as $$ declare ret record; begin for ret in (select oid::int,datname::text from pg_database limit 1) loop return ret; end loop; end; $$ language plpgsql;
CREATE FUNCTION
your call:
t=# select f();
f
------------------
(13505,postgres)
(1 row)
expected call:
t=# select * from f() as r(o int,n text);
o | n
-------+----------
13505 | postgres
(1 row)
and if you want to predefine the structure of record to be called implicitely, you can create a dummy fn():
t=# create or replace function dummy() returns table (a int,b text) as $$ begin return query select * from f() as r(o int,n text); end; $$ language plpgsql;
CREATE FUNCTION
t=# select * from dummy();
a | b
-------+----------
13505 | postgres
(1 row)
of if you want to avoid FROM:
t=# select (dummy()).*;
a | b
-------+----------
13505 | postgres
(1 row)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With