postgresql/lightdb行构造器ROW函数的使用

最近研究PG源码时,遇到行构造器的特性。官方文档https://www.postgresql.org/docs/current/functions-comparisons.html#ROW-WISE-COMPARISON并未给出ROW构造器的示例。

ROW()对应的实现是RowExpr(里面解析后会存储各种字段的明细信息以及对应的record的oid),其实就是匿名记录类型。8.1之后也支持row(t.*),t为表名,主要是为了针对集合比较写代码更省事。

lightdb@oradb=# select row(t.*) from big_table t where row(t.*) is not null limit 3;
row
------------------------------------------
(1,57ccab02-9546-4784-99e1-7b7b8eadda56)
(2,a0d871d5-e3a9-494d-8aec-12d739e0b1ce)
(3,3e08a87c-55b4-438f-b78c-cd0d7f69d720)
(3 rows)
lightdb@oradb=# select row(t.*) from big_table t where row(t.*) in (select * from big_table limit 2);
row
------------------------------------------
(1,57ccab02-9546-4784-99e1-7b7b8eadda56)
(2,a0d871d5-e3a9-494d-8aec-12d739e0b1ce)
(2 rows)
SELECT ROW(1,2.5,'this is a test') = ROW(1, 3, 'not the same');

SELECT ROW(table.*) IS NULL FROM table;  -- detect all-null rows

https://www.postgresql.org/docs/current/sql-expressions.html#SQL-SYNTAX-ROW-CONSTRUCTORS

http://www.java2s.com/Code/PostgreSQL/Select-Query/RowConstructors.htm

https://dba.stackexchange.com/questions/275601/why-is-the-row-keyword-needed-when-constructing-a-row-with-one-element-but-not

posted @   zhjh256  阅读(142)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
历史上的今天:
2020-01-15 org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection总结
2020-01-15 dubbo 2.5.3 curator Path cannot be null bug
2017-01-15 使用openssl生成SSL证书完全参考手册
点击右上角即可分享
微信分享提示