public inbox for [email protected]help / color / mirror / Atom feed
Return a table from a function 3+ messages / 2 participants [nested] [flat]
* Return a table from a function @ 2021-04-06 16:52 Simon Connah <[email protected]> 0 siblings, 1 reply; 3+ messages in thread From: Simon Connah @ 2021-04-06 16:52 UTC (permalink / raw) To: [email protected] <[email protected]> Hi, I've written a function that returns a table. It works fine and I get the expected results. The only problem is that in Node.js which is the client the table data is a string rather than a list of variables. Is there some way to change the return data so it is still like a table but in something like JSON? Or even better is there a way to return it as the individual rows so that each column can be easily accessed? I'm using pg-promise to access PostgreSQL from a Node.js web application. Simon. Attachments: [application/pgp-signature] signature.asc (249B, ../../b6uFTyH937VOq3XGPT7xAS9Po7-3kwphF834W8eNTl4od008FNoSKn7HPlQnUooaVdk0t1ATa3b6PxJFh3pqF87VTLNJ82VTUXhMkjEqsAs=@protonmail.com/2-signature.asc) download ^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Return a table from a function @ 2021-04-07 08:44 Laurenz Albe <[email protected]> parent: Simon Connah <[email protected]> 0 siblings, 1 reply; 3+ messages in thread From: Laurenz Albe @ 2021-04-07 08:44 UTC (permalink / raw) To: Simon Connah <[email protected]>; [email protected] <[email protected]> On Tue, 2021-04-06 at 16:52 +0000, Simon Connah wrote: > I've written a function that returns a table. It works fine and I get the expected results. > The only problem is that in Node.js which is the client the table data is a string rather > than a list of variables. Is there some way to change the return data so it is still like > a table but in something like JSON? Or even better is there a way to return it as the > individual rows so that each column can be easily accessed? I'm using pg-promise to access > PostgreSQL from a Node.js web application. It's a bit unclear what you are doing, but I guess you should run SELECT * FROM myfunction('arg'); rather than SELECT myfunction('arg'); Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com ^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Return a table from a function @ 2021-04-07 11:54 Simon Connah <[email protected]> parent: Laurenz Albe <[email protected]> 0 siblings, 0 replies; 3+ messages in thread From: Simon Connah @ 2021-04-07 11:54 UTC (permalink / raw) To: Laurenz Albe <[email protected]>; +Cc: [email protected] <[email protected]> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Wednesday, April 7th, 2021 at 09:44, Laurenz Albe <[email protected]> wrote: > On Tue, 2021-04-06 at 16:52 +0000, Simon Connah wrote: > > > I've written a function that returns a table. It works fine and I get the expected results. > > > > The only problem is that in Node.js which is the client the table data is a string rather > > > > than a list of variables. Is there some way to change the return data so it is still like > > > > a table but in something like JSON? Or even better is there a way to return it as the > > > > individual rows so that each column can be easily accessed? I'm using pg-promise to access > > > > PostgreSQL from a Node.js web application. > > It's a bit unclear what you are doing, but I guess you should run > > SELECT * FROM myfunction('arg'); > > rather than > > SELECT myfunction('arg'); > > Yours, > > Laurenz Albe > ------------------------------------------------------------------------------------------------------------------------------------------------------------------- > > Cybertec | https://www.cybertec-postgresql.com That fixed it perfectly! Thank you. Attachments: [application/pgp-signature] signature.asc (249B, ../../ZFN0GPmc3-cvrruskEt1dlawlju5kby21xy_MW1xJTxNv_UtGTWQXpviTt9jn7cM30t6e3YtQwLFSwXpmf9IjYK86jAc5BXT5E6uQVJP6T8=@protonmail.com/2-signature.asc) download ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2021-04-07 11:54 UTC | newest] Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-04-06 16:52 Return a table from a function Simon Connah <[email protected]> 2021-04-07 08:44 ` Laurenz Albe <[email protected]> 2021-04-07 11:54 ` Simon Connah <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox