选择复合类型数组的条件(postgresql)
例如,我有类型:
CREATE TYPE record AS ( name text, description text, tags text[])
和表:
CREATE TABLE items ( id serial, records record[] )
如何选择带有标签“test”的记录的所有项目(不使用 PL/pgSQL)?
For example I have type:
CREATE TYPE record AS ( name text, description text, tags text[])
And table:
CREATE TABLE items ( id serial, records record[] )
How can I select all items with records with tags 'test' (without using PL/pgSQL)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么大家都想用数组、hstore等搬起石头砸自己的脚?将数据规范化为标准 SQL 表。并在编程时使用数组、hstore 等高级功能。但这里有一个要点……
Postgres 不会喜欢你使用保留字作为类型。
在一个数组中、另一个数组中的复合体中搜索文本……这真是令人难以置信。即使你确实弄清楚了,任何追随你试图维护你的代码的人都会摸不着头脑。
Why does everyone want to shoot themselves in the foot with arrays, hstores, etc? Normalize your data into standard SQL tables. And use advanced features like arrays, hstores when you are programming. But here's a bullet...
Postgres isn't going to like your use of a reserved word as a type.
And searching for text in an array, in a composite in another array... well that just boggles the mind. And even if you did figure it out, anyone who came after you trying to maintain your code would be left scratching their heads.