Re: string = any()
От | David Johnston |
---|---|
Тема | Re: string = any() |
Дата | |
Msg-id | 015101cccfab$0206f770$0614e650$@yahoo.com обсуждение исходный текст |
Ответ на | string = any() (Andy Colson <andy@squeakycode.net>) |
Ответы |
Re: string = any()
|
Список | pgsql-general |
-----Original Message----- From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Andy Colson Sent: Tuesday, January 10, 2012 10:04 AM To: PostgreSQL Subject: [GENERAL] string = any() 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 ------------------------------------------------------------------------ Explicit casting is required otherwise the system simply treats you input as a simple scalar varchar. " SELECT 'bob' = ANY( $1::varchar[] ) ... " You can also pass in a delimited string and perform a "split_to_array($1, ',')" - didn't check exact syntax but you get the idea David J.
В списке pgsql-general по дате отправления: