public inbox for [email protected]  
help / color / mirror / Atom feed
From: Laurenz Albe <[email protected]>
To: Simon Connah <[email protected]>
To: [email protected] <[email protected]>
Subject: Re: Return a table from a function
Date: Wed, 07 Apr 2021 10:44:08 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <b6uFTyH937VOq3XGPT7xAS9Po7-3kwphF834W8eNTl4od008FNoSKn7HPlQnUooaVdk0t1ATa3b6PxJFh3pqF87VTLNJ82VTUXhMkjEqsAs=@protonmail.com>
References: <b6uFTyH937VOq3XGPT7xAS9Po7-3kwphF834W8eNTl4od008FNoSKn7HPlQnUooaVdk0t1ATa3b6PxJFh3pqF87VTLNJ82VTUXhMkjEqsAs=@protonmail.com>

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






view thread (3+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Return a table from a function
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox