开发者

How to pass integer array into IN clause?

I want to pass an integer array from input parameters of my postgresql function into sql IN clause.

I开发者_如何学编程nto what and how I can convert such array?


I had same problem lately.

Look here:

http://postgresql.1045698.n5.nabble.com/Using-PL-pgSQL-text-argument-in-IN-INT-INT-clause-re-post-td3235644.html

Hope it helps.

Here is a sample function:

CREATE OR REPLACE FUNCTION "GetSetOfObjects"(ids text)
  RETURNS SETOF record AS
$BODY$select *
from objects
where id = any(string_to_array($1,',')::integer[]);$BODY$
  LANGUAGE sql IMMUTABLE


Basically you can't. What you can do is pass in a comma-delimited list and split it apart in your function. Here are some examples using SQL Server, but I'm sure they can be translated.

Unless this (PostgreSQL) is what you're talking about.


i usually use implicit conversion

select '{1,2,3,4,5}' :: integer[]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜