Re:

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re:
Дата
Msg-id 43C38629.6030508@magproductions.nl
обсуждение исходный текст
Ответ на Re:  (Matthew Peter <survivedsushi@yahoo.com>)
Список pgsql-general
Matthew Peter wrote:
> CREATE OR REPLACE FUNCTION getlist(text) RETURNS SETOF my_tbl as $$
> SELECT * FROM my_tbl
> WHERE u_id IN (0, $1);
>
> $$ LANGUAGE SQL;
>
> SELECT * from getlist('1,2,3');
> (0 rows)

You're executing SELECT * FROM my_tbl WHERE u_id IN (0, '1,2,3').
Apparently there are no values 0 or '1,2,3' for u_id in that table.

> I'm sure it's probably trival but I'm still learning how psql  :) Thanks

You can split the string into values with string_to_array(). You'll
still be comparing ints with strings though.

Without casting the resulting strings to ints you run the risk that the
database needs to cast the int u_id value to text for every record
encountered. For 'small' data sets this shouldn't be a problem.

I suppose this is a simplified example, or you wouldn't have a reason to
use an SP; you'd just SELECT * FROM my_tbl WHERE u_id IN (0,1,2,3)

--
Alban Hertroys
alban@magproductions.nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
    7500 AK Enschede

//Showing your Vision to the World//

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

Предыдущее
От: Nico Callewaert
Дата:
Сообщение: Best programming language / connectivity for best performance
Следующее
От: "surabhi.ahuja"
Дата:
Сообщение: regarding triggers