如何确定范围列表是否包含指定的整数
产品类型表包含产品类型。可能会丢失一些ID:
create table artliik (liiginrlki char(3) primary key);
insert into artliik values('1');
insert into artliik values('3');
insert into artliik values('4');
...
insert into artliik values('999');
属性表Contais Comma分离的类型列表。
create table strings ( id char(100) primary key, kirjeldLku chr(200) );
insert into strings values ('item1', '1,4-5' );
insert into strings values ('item2', '1,2,3,6-9,23-44,45' );
类型可以指定为单个整数,等式1,2,3或范围6-9或23-44 列表可以包含两个。
如何用于给定类型的所有属性。 查询
select id
from artliik
join strings on ','||trim(strings.kirjeldLku)||',' like '%,'||trim(artliik.liiginrlki)||',%'
单个整数列表的返回日期。 如何更改加入加入,以便返回列表中的该类型范围,也可以返回6-9的范围? 等式。 F列表包含报告中包含的6-9,6,7,8和9 shoud。
使用Postgres 13。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议使用类似于
Un -nest
的辅助功能,以纪念范围。校正函数
然后您可以'归一化'表
字符串
并加入。函数定义的使用当然是可选的。我更喜欢它,因为该功能是通用和可重复使用的。
I would suggest a helper function similar to
unnest
that honors ranges.Corrected function
Then you can 'normalize' table
strings
and join.The use of a function definition is of course optional. I prefer it because the function is generic and reusable.
COLATION DOC: https://www.postgresql.org.org.org/docsql.org/docs/current/current/collent/collent/collation.html.
想法:创建一个多级文本数据类型,该数据类型将根据其数值值对数字值进行排序。像“ A-21”< 'A-123'。
因此,
应返回 true 。
Artliik表结构保持不变,但是Strings表需要更改。
然后查询它:
dbfiddle.uk demo will only works on pg14, since only pg14 have multirange data type. But customizeable icu collation works in pg13.
Collation doc: https://www.postgresql.org/docs/current/collation.html
Idea: create a multirange text data type that will sort numeric value based on their numerical value. like 'A-21' < 'A-123'.
So
should return true.
artliik table structure remain the same, but strings table need to change a bit.
then query it: