Re: Why does this array query fail? - Mailing list pgsql-general

From Ken Tanzer
Subject Re: Why does this array query fail?
Date
Msg-id CAD3a31VHQzCsvO1xs+29c3t85DPdtUWtww947Mo=MvikQ5dwdw@mail.gmail.com
Whole thread Raw
In response to Re: Why does this array query fail?  (bricklen <bricklen@gmail.com>)
Responses Re: Why does this array query fail?  (Ken Tanzer <ken.tanzer@gmail.com>)
List pgsql-general
OK I tried that and see it works with the cast.  But now I'm confused about both what exactly is failing without the cast, and about the resulting error message.

Is the query failing because PG doesn't understand the subquery is yielding an array?  Seems unlikely.  But if the problem is a type mismatch between 'test' (on the left) and my subquery, I'd expect the same error message as if I try to compare an int to a text array:

SELECT 'found' WHERE 1 = ANY( (SELECT ARRAY['test','pass','fail']));
ERROR:  operator does not exist: integer = text[]
LINE 1: SELECT 'found' WHERE 1 = ANY( (SELECT ARRAY['test','pass','f...
                               ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

Instead of the error message I actually got:

ERROR:  array value must start with "{" or dimension information

Thanks.

Ken





On Mon, Sep 16, 2013 at 6:42 PM, bricklen <bricklen@gmail.com> wrote:

On Mon, Sep 16, 2013 at 6:36 PM, Ken Tanzer <ken.tanzer@gmail.com> wrote:
Thanks for the explanation.  I think I at least understand what it's doing now.  I'm either surprised or confused though, as I was under the impression that you could substitute a subquery for a value pretty much anywhere, but I guess that's not the case?

Cheers,
Ken


Your subquery can also be explicitly casted to make it work. Note the "::TEXT[]"

SELECT 'found' WHERE 'test' = ANY( (SELECT ARRAY['test','pass','fail'])::TEXT[] );



--
AGENCY Software  
A data system that puts you in control
100% Free Software
(253) 245-3801

learn more about AGENCY or
follow the discussion.

pgsql-general by date:

Previous
From: bricklen
Date:
Subject: Re: Why does this array query fail?
Next
From: Ken Tanzer
Date:
Subject: Re: Why does this array query fail?