Re: string = any()

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: string = any()
Дата
Msg-id 01ff01cccfe2$20fc83c0$62f58b40$@yahoo.com
обсуждение исходный текст
Ответ на Re: string = any()  (Filip Rembiałkowski <plk.zuber@gmail.com>)
Ответы Re: string = any()  (Filip Rembiałkowski <plk.zuber@gmail.com>)
Список pgsql-general
-----Original Message-----
From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Filip Rembialkowski
Sent: Tuesday, January 10, 2012 4:27 PM
To: Andy Colson
Cc: PostgreSQL
Subject: Re: [GENERAL] string = any()


no, I meant array constructor with reserved word ARRAY:

prepare x as select 'bob' = any( ARRAY[$2,$3] );
execute x( 'joe', 'bob' );

and in PHP:
<?php
$names = array( "joe", "bob" );
$placeholders = implode( ",", array_map( function($x){return "?"},
$names ) ); #I love Perl
$sql = "select 'bob' = any( ARRAY[$placeholders] )";
$stmt = $dbh->prepare($sql);
$stmt->execute($names);
?>

-----------------------------------------------------------------------------
Filip,

If you are going to supply one parameter per "possible value" anyway skip the whole "ANY" and "ARRAY" and just say "
'bob'IN ($1, $2 [,...]) ";  The whole point of the exercise is to avoid dynamic SQL on the language side by ALWAYS
havinga single input regardless of how many possible values exists.  Now, ideally you could pass in an actual ARRAY
objectfrom your programming language but as that, for whatever reason, tends to be clumsy or difficult the next best
optionis to pass in a single delimited string and then let PostGRESql convert it into an ARRAY and then use "=
ANY($1)".

David J.



В списке pgsql-general по дате отправления:

Предыдущее
От: Yoann MOREAU
Дата:
Сообщение: Efficient map looking table
Следующее
От: "David Johnston"
Дата:
Сообщение: Re: Efficient map looking table