试试这个:
create table x(d timestamp);insert into x values('jan 2, 2012'),('february 4, 2012 12:00'),('jan 4, 2012 12:00'),('march 1, 2012'),('may 3, 2012');询问:
with input as( select '2012-1-2, 2012-01-04 12:00, 2012-02-04 12:00, 2012-03-04 12:00'::text as d_input),converted_to_array as( select ('{' || d_input || '}')::timestamp[] as d_array from input )select dfrom x cross join converted_to_arraywhere d = any(d_array)输出:
DJanuary, 02 2012 00:00:00-0800February, 04 2012 12:00:00-0800January, 04 2012 12:00:00-0800
实时测试:http://www.sqlfiddle.com/#!1 /
43d48 / 26
您还可以使用IN,只是将数组嵌套到行:
with input as( select '2012-1-2, 2012-01-04 12:00, 2012-02-04 12:00, 2012-03-04 12:00'::text as d_input),converted_to_array as( select ('{' || d_input || '}')::timestamp[] as d_array from input )select dfrom x cross join converted_to_arraywhere d in (select unnest(d_array))实时测试:http://www.sqlfiddle.com/#!1
/ 43d48 /
29
您也可以将它们全部放在一行中:
select dfrom x where d in (select unnest( ('{' || '2012-1-2, 2012-01-04 12:00, 2012-02-04 12:00, 2012-03-04 12:00'::text || '}')::timestamp[] ))但我犹豫这样做,因为这会在stackoverflow上引起水平滚动条:-)
实时测试:http://www.sqlfiddle.com/#!1 /
43d48 / 31



