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 1iDFvb-0000j6-VX for pgsql-general@arkaria.postgresql.org; Wed, 25 Sep 2019 22:38:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iDFva-0004iE-BH for pgsql-general@arkaria.postgresql.org; Wed, 25 Sep 2019 22:38:30 +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 1iDFvZ-0004i3-VY for pgsql-general@lists.postgresql.org; Wed, 25 Sep 2019 22:38:30 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iDFvX-0006xV-Nd for pgsql-general@postgresql.org; Wed, 25 Sep 2019 22:38:28 +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 x8PMcPjv028609; Wed, 25 Sep 2019 18:38:25 -0400 From: Tom Lane To: Alban Hertroys cc: David Salisbury , pgsql-general@postgresql.org Subject: Re: Arrays and ANY problem In-reply-to: <526FB575-7D50-4D11-A053-8B4B66D5200F@gmail.com> References: <775E048E-4316-4AFE-B4A7-A25AC79DE002@gmail.com> <526FB575-7D50-4D11-A053-8B4B66D5200F@gmail.com> Comments: In-reply-to Alban Hertroys message dated "Wed, 25 Sep 2019 22:54:49 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <28607.1569451105.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 25 Sep 2019 18:38:25 -0400 Message-ID: <28608.1569451105@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alban Hertroys writes: >> On 25 Sep 2019, at 22:50, Alban Hertroys wrote: >> You probably meant: >> select name from table_name_ds_tmp where categoryid =3D ANY ( select st= ring_to_array( '200,400', ',')::bigint[] ); > Or rather: > select name from table_name_ds_tmp where categoryid =3D ANY ( string_to_= array( '200,400', ',')::bigint[] ); Yeah, this is fairly confusing, because there are multiple different features with barely distinguishable syntaxes here. You can do value =3D ANY (SELECT ...) which compares "value" to each row of the sub-SELECT result (and the sub-SELECT had better return one column, of a type comparable to "value"). Or you can do value =3D ANY (array-expression) which compares "value" to each element of the array value (which had better have elements of a type comparable to "value"). What you can't do is generate the array value from a sub-select, because that will be taken as being an instance of the first feature. David didn't say what his real problem was, but I'd suggest that making his sub-select return a rowset result rather than an array result might be the best way to resolve things. It's more SQL-y, for sure. regards, tom lane