From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> |
Cc: | Alexander Farber <alexander(dot)farber(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: How to return ARRAY from SQL function? |
Date: | 2019-06-14 13:25:32 |
Message-ID: | 27773.1560518732@sss.pgh.pa.us |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2019-06-14 13:47:37 | Re: How to connect to toad Edge with postgresql running with docker container? |
Previous Message | Laurenz Albe | 2019-06-14 11:17:07 | Re: How to return ARRAY from SQL function? |