Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lU3nL-0008BH-Gk for pgsql-novice@arkaria.postgresql.org; Wed, 07 Apr 2021 08:44:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lU3nK-0002G5-8e for pgsql-novice@arkaria.postgresql.org; Wed, 07 Apr 2021 08:44:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lU3nJ-0002Fx-TZ for pgsql-novice@lists.postgresql.org; Wed, 07 Apr 2021 08:44:14 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lU3nG-0007xo-U0 for pgsql-novice@lists.postgresql.org; Wed, 07 Apr 2021 08:44:13 +0000 Received: by mail-ed1-x533.google.com with SMTP id s15so4865318edd.4 for ; Wed, 07 Apr 2021 01:44:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=71d+ibK3RypV3lVFopp9TbVQvAc0cdlAIqPFnPQCz7w=; b=q5uDC4/FGmymWMwc+wr8jfwQc3sIE+TWpp8d+5P5vmfl27CJoXQ6goRDKkRL30kTsn w6e37hq/vxSw77e95uBzY0goC2QK1RLW4Q9RjVExLZD0v1jGaff4G1D+OAiilGZAm/mo 6OcMEosS4XH7X2P21CvqzjBLrW20voqjxgaY+pWZ4nFBbtSXiDO9T9AtforAuR0nNuWk hdQfsXcFEKCzc3nWagRbnc83pajHqj+iIEm9j4KtsuGBWOcSpNT6rMNfPVLmrtNzE/j/ 0IJG1cVPwrL7uYnKzDsl+a296rK+UTEqwmK3jaSR5zeqW6vkE/5TVpN29/0ZcR9Bu5iT c9Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=71d+ibK3RypV3lVFopp9TbVQvAc0cdlAIqPFnPQCz7w=; b=erm6c0jlJkRteerANOSGPsrwwJGaN1sJrn80ogADIB+JtXZkjamXkUYYi7/Qrlz3Ex ugPw+3N5KfHy4rwTnar8aw1OzMFTX1FULSBkDWoEm5z77LfCviera+I12b/JRE6mLW5/ wvnEuqJ8pSkiwU0KQ36Z7DWUBZQ53ZhZGJpCO/2TXmy1RI1b23pQx+D962KQphLix/qk iF7eOYCd0L/VqLOJdtDQVersVlbWaWrPCLGvqxjZ2EgzHZxtcRNhCMeJTAfv4U2DOXN6 5FAQta1KgQsII/PUHbYO9bzuz3rp5D/qcgHzs8FllnnMVKzOzN9WRDwEFVDduer0eCBP CORw== X-Gm-Message-State: AOAM5323V7ABgGHd5bQl+zZDdaytEzYppQeQOCcf1LjN1zS93DF1wi9n Zi7K1+0B6wdG3ENPFcbkJwDL1qL6OhYVrw== X-Google-Smtp-Source: ABdhPJzNnZQM+yXliuDr3OguyYrM7iS6hD0SQE3ntJCe5zxXxwCrghoZe/Oprxpc/MJurJpgjtVUdA== X-Received: by 2002:aa7:c0ca:: with SMTP id j10mr747599edp.291.1617785050009; Wed, 07 Apr 2021 01:44:10 -0700 (PDT) Received: from localhost.localdomain (178-190-172-163.adsl.highway.telekom.at. [178.190.172.163]) by smtp.gmail.com with ESMTPSA id z4sm2435795edb.97.2021.04.07.01.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Apr 2021 01:44:09 -0700 (PDT) Message-ID: <1f660bc35d01cd27112dde5b01ef9b32bab92c16.camel@cybertec.at> Subject: Re: Return a table from a function From: Laurenz Albe To: Simon Connah , "pgsql-novice@lists.postgresql.org" Date: Wed, 07 Apr 2021 10:44:08 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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