From: | Andy Colson <andy(at)squeakycode(dot)net> |
---|---|
To: | Filip Rembiałkowski <plk(dot)zuber(at)gmail(dot)com> |
Cc: | PostgreSQL <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: string = any() |
Date: | 2012-01-10 15:17:40 |
Message-ID: | 4F0C5694.4030409@squeakycode.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
>
> 2012/1/10 Andy Colson<andy(at)squeakycode(dot)net>:
>> Hi all.
>>
>> I am writing PHP where it prepares a statement like:
>> $sql = 'select * from aTable where id = any($1)';
>>
>> then in php I create a string:
>> $args = "{1,2,3}";
>>
>> And run it:
>>
>> $q = pg_query_params($db, $sql, $args);
>>
>> This is not actual code, just a sample. And it works great for integers. I
>> cannot get it to work with strings.
>>
>> Just running this in psql does not work either:
>> select 'bob' = any( '{''joe'', ''bob'' }' )
>>
>> But this does:
>> select 'bob' = any( array['joe', 'bob'] )
>>
>> But I can't seem to prepare and execute:
>> $sql = "select 'bob' = any( $1 )";
>> $args = "array['joe', 'bob']";
>> $q = pg_query_params($db, $sql, $args);
>>
>> Running on 9.0.4 on Slackware 64.
>>
>> Any hits would be appreciated.
>>
>> -Andy
>>
>> --
>> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-general
>
On 1/10/2012 9:11 AM, Filip Rembiałkowski wrote:
> maybe try to use ARRAY constructor instead?
>
http://www.postgresql.org/docs/9.0/static/sql-expressions.html#SQL-SYNTAX-ARRAY-CONSTRUCTORS
>
>
As I mentioned, I cannot get it to work:
clayia=# prepare x as select 'bob' = any($1);
PREPARE
Time: 0.665 ms
clayia=# execute x( 'array[''joe'', ''bob'']' );
ERROR: array value must start with "{" or dimension information
LINE 1: execute x( 'array[''joe'', ''bob'']' );
-Andy
From | Date | Subject | |
---|---|---|---|
Next Message | David Johnston | 2012-01-10 15:17:46 | Re: string = any() |
Previous Message | Filip Rembiałkowski | 2012-01-10 15:11:28 | Re: string = any() |