Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hbmDH-0002UP-DG for pgsql-general@arkaria.postgresql.org; Fri, 14 Jun 2019 13:25:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hbmDF-0006L8-8J for pgsql-general@arkaria.postgresql.org; Fri, 14 Jun 2019 13:25:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hbmDE-0006Kt-S6 for pgsql-general@lists.postgresql.org; Fri, 14 Jun 2019 13:25:48 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hbmD8-00038N-El for pgsql-general@postgresql.org; Fri, 14 Jun 2019 13:25:47 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x5EDPW9Y027774; Fri, 14 Jun 2019 09:25:33 -0400 From: Tom Lane To: Laurenz Albe cc: Alexander Farber , pgsql-general Subject: Re: How to return ARRAY from SQL function? In-reply-to: References: Comments: In-reply-to Laurenz Albe message dated "Fri, 14 Jun 2019 13:17:07 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <27772.1560518732.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Fri, 14 Jun 2019 09:25:32 -0400 Message-ID: <27773.1560518732@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Laurenz Albe 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