I have a 'route' table describe as follows:
CREATE TABLE NEW_ROUTES (
id integer primary key,
path integer[],
name text
);
And I added some rows:
insert into NEW_ROUTES (id,path,name)
values (1, '{1,2,3,4}', 'path1');
insert into NEW_ROUTES (id,path,name)
values (2, '{1,2,3,4,5}', 'path2');
insert into NEW_ROUTES (id,path,name)
values (3, '{5,4,3,2}', 'path3');
insert into NEW_ROUTES (id,path,name)
values (4, '{2,3,1,7}', 'path4');
insert into NEW_ROUTES (id,path,name)
values (5, '{7,6,5,4,3}', 'path5');
insert into NEW_ROUTES (id,path,name)
values (6, '{1,2}', 'path6');
insert into NEW_ROUTES (id,path,name)
values (7, '{2,1}', 'path7');
insert into NEW_ROUTES (id,path,name)
values (8, '{2,7,5,1,9}', 'path8');
- How can I select multiple rows, which have integers 1 and 2 and where 2 is placed before 1 (for example, {2,1} and {2,7,5,1,9} etc..).
- Which type of index should i use (for example, GIN)?
- Is there another and best way to solve this problem (for example, using string, json, tree or smth else)?
I will be appreciated if you help me.