pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alban Hertroys <haramrae@gmail.com>
Cc: David Salisbury <dsalis@ucar.edu>
Cc: pgsql-general@postgresql.org
Subject: Re: Arrays and ANY problem
Date: Wed, 25 Sep 2019 18:38:25 -0400
Message-ID: <28608.1569451105@sss.pgh.pa.us> (raw)
In-Reply-To: <526FB575-7D50-4D11-A053-8B4B66D5200F@gmail.com>
References: <CAKXTjVmV+mHXvzCKtKuHeooYYObNQhST7eG7kJmUcJy7=1cqTg@mail.gmail.com>
	<775E048E-4316-4AFE-B4A7-A25AC79DE002@gmail.com>
	<526FB575-7D50-4D11-A053-8B4B66D5200F@gmail.com>

Alban Hertroys <haramrae@gmail.com> writes:
>> On 25 Sep 2019, at 22:50, Alban Hertroys <haramrae@gmail.com> wrote:
>> You probably meant:
>> select name from table_name_ds_tmp where categoryid = ANY ( select string_to_array( '200,400', ',')::bigint[] );

> Or rather:
> select name from table_name_ds_tmp where categoryid = 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 = 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 = 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





view thread (9+ messages)  latest in thread

Message-ID: <28608.1569451105@sss.pgh.pa.us>
Permalink:  ../28608.1569451105@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/28608.1569451105@sss.pgh.pa.us

 · 

reply

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, haramrae@gmail.com, dsalis@ucar.edu
  Subject: Re: Arrays and ANY problem
  In-Reply-To: <28608.1569451105@sss.pgh.pa.us>
  References: <CAKXTjVmV+mHXvzCKtKuHeooYYObNQhST7eG7kJmUcJy7=1cqTg@mail.gmail.com> <775E048E-4316-4AFE-B4A7-A25AC79DE002@gmail.com> <526FB575-7D50-4D11-A053-8B4B66D5200F@gmail.com> <28608.1569451105@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