小编mlp*_*lpo的帖子

查找整数序列包含给定子序列的行

问题

注意:我指的是数学序列,而不是PostgreSQL序列机制

我有一个表示整数序列的表。定义是:

CREATE TABLE sequences
(
  id serial NOT NULL,
  title character varying(255) NOT NULL,
  date date NOT NULL,
  sequence integer[] NOT NULL,
  CONSTRAINT "PRIM_KEY_SEQUENCES" PRIMARY KEY (id)
);
Run Code Online (Sandbox Code Playgroud)

我的目标是使用给定的子序列查找行。也就是说,sequence字段是包含给定子序列的序列的行(在我的情况下,序列是有序的)。

例子

假设该表包含以下数据:

+----+-------+------------+-------------------------------+
| id | title |    date    |           sequence            |
+----+-------+------------+-------------------------------+
|  1 | BG703 | 2004-12-24 | {1,3,17,25,377,424,242,1234}  |
|  2 | BG256 | 2005-05-11 | {5,7,12,742,225,547,2142,223} |
|  3 | BD404 | 2004-10-13 | {3,4,12,5698,526}             |
| …
Run Code Online (Sandbox Code Playgroud)

schema postgresql performance array

9
推荐指数
1
解决办法
1357
查看次数

标签 统计

array ×1

performance ×1

postgresql ×1

schema ×1