any用法
最近更新时间: 2025-02-18 16:02:00
示例1、
postgres=# create table t_any(id int,mc text);
CREATE TABLE
postgres=# insert into t_any values(1,'TDSQL PG'),(2,'TDSQL PG');
INSERT 0 2
postgres=# select * from t_any where id>any (select 1 union select 3);
id | mc
----+-------
2 | TDSQL PG
(1 row)
只需要大于其中一个值即为真。
示例2、
drop table if exists t_any_dml_20220718_1;
create table t_any_dml_20220718_1(v int, w int);
insert into t_any_dml_20220718_1 values(1, 1);
insert into t_any_dml_20220718_1 values(2, 2);
update t_any_dml_20220718_1 set w = 3 where w > any(0, 1);
delete t_any_dml_20220718_1 where w > any(0, 1);
insert into t_any_dml_20220718_1 values(1, 1);
insert into t_any_dml_20220718_1 select 2, 2 from t_any_dml_20220718_1 where w <> any(0, 1);
with cte_any_update as (select v from t_any_dml_20220718_1 where v > any(0, 1)) update t_any_dml_20220718_1 set w = (select v from cte_any_update order by v limit 1) where w > all(0, 1);
select * from t_any_dml_20220718_1 order by v;
with cte_any_delete as (select v from t_any_dml_20220718_1 where v > any(0, 1)) delete t_any_dml_20220718_1 where w = any(select v from cte_any_delete order by v limit 1);
select * from t_any_dml_20220718_1 order by v;
insert into t_any_dml_20220718_1 values(1, 1);
with cte_any_insert as (select v, w from t_any_dml_20220718_1 where v > any(0, 1)) insert into t_any_dml_20220718_1 select v, w from cte_any_insert;
select * from t_any_dml_20220718_1 order by v;