Re: string = any()

From: "David Johnston" <polobo(at)yahoo(dot)com>
To: "'Andy Colson'" <andy(at)squeakycode(dot)net>
Cc: "'PostgreSQL'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: string = any()
Date: 2012-01-10 16:28:39
Message-ID: 016701cccfb4$e9d253c0$bd76fb40$@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Andy Colson
Sent: Tuesday, January 10, 2012 11:20 AM
To: David Johnston
Cc: 'PostgreSQL'
Subject: Re: [GENERAL] string = any()

> This still does not work, even in psql:
> select 'bob' = any( '{''joe'', ''bob'' }'::varchar[] )
>
> $$ ^ This works for me just fine....though I am not using psql; are
> you having quoting issues? What error do you get?
>

It runs, but it returns false. I get false at least. I'm assuming you do
to, otherwise something weird is going on.

-----------------------------------------

I execute the following:

SELECT 'bob' = ANY( '{ "joe", "bob" }'::varchar[] );

And it returns TRUE...

This returns FALSE:

SELECT 'bob' = ANY( '{ "joe", "dave" }'::varchar[] );

I didn't enable logging so I don't know exactly what the engine is seeing
but using PostgreSQL Maestro that is what I am getting; and from the
documentation it seems correct...

I am using the "string_to_array()" function call where I do this kind of
thing because I probably encountered the same Java API issue that you are
with PHP; but since passing in the delimited string and splitting it isn't
that difficult I am not all that concerned. You need to embed the
"string_to_array" inside the prepared statement and pass only scalars via
the API.

So:

prepare x as select 'bob' = any(string_to_array($1, ',')::varchar[]);
execute x ('joe,bob,billy');

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ernesto Quiñones 2012-01-10 16:30:36 Re: Two indexes on same column
Previous Message Andy Colson 2012-01-10 16:19:55 Re: string = any()