From: Tom Lane <tgl@sss.pgh.pa.us>
To: Laurenz Albe <laurenz.albe@cybertec.at>
Cc: Alexander Farber <alexander.farber@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: How to return ARRAY from SQL function?
Date: Fri, 14 Jun 2019 09:25:32 -0400
Message-ID: <27773.1560518732@sss.pgh.pa.us> (raw)
In-Reply-To: <fa667d56acfa4f4bd40556ddc1ef86e63a47a9dc.camel@cybertec.at>
References: <CAADeyWgc-dXvuPP+Sq-xsLiauKdTZYmuco9xePa2y0a0x1PTKw@mail.gmail.com>
<fa667d56acfa4f4bd40556ddc1ef86e63a47a9dc.camel@cybertec.at>
Laurenz Albe <laurenz.albe@cybertec.at> writes:
> Alexander Farber wrote:
>> But creating an SQL function fails -
>>
>> words_ru=> CREATE OR REPLACE FUNCTION words_all_letters()
>> words_ru-> RETURNS array AS
>> words_ru-> $func$
>> words_ru$> SELECT ARRAY[...
> "array" is not an existing data type.
> You'll have to specify an array of which type you want, probably
> ... RETURNS text[]
Right. Also, I don't recall the exact rules in this area, but I think
that SQL functions are pickier about their return types than ordinary
query contexts, meaning you might also need an explicit cast:
SELECT ARRAY[
'*', '*', 'А', 'А', 'А', 'А', 'А', 'А', 'А', 'А',
...
]::text[];
Try it without first, but if it moans about the query returning the
wrong type, that's how to fix it.
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, laurenz.albe@cybertec.at, alexander.farber@gmail.com
Subject: Re: How to return ARRAY from SQL function?
In-Reply-To: <27773.1560518732@sss.pgh.pa.us>
References: <CAADeyWgc-dXvuPP+Sq-xsLiauKdTZYmuco9xePa2y0a0x1PTKw@mail.gmail.com> <fa667d56acfa4f4bd40556ddc1ef86e63a47a9dc.camel@cybertec.at> <27773.1560518732@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox