Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nucip-0006HJ-AP for pgsql-general@arkaria.postgresql.org; Fri, 27 May 2022 16:21:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nucio-0002tz-6A for pgsql-general@arkaria.postgresql.org; Fri, 27 May 2022 16:21:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nuXYz-0003AQ-FM for pgsql-general@lists.postgresql.org; Fri, 27 May 2022 10:51:25 +0000 Received: from portal-smtp-out.hot.ee ([194.126.101.125]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nuXYw-0002pI-3P for pgsql-general@postgresql.org; Fri, 27 May 2022 10:51:24 +0000 Received: from localhost (localhost [127.0.0.1]) by vm-hot-relay10.estpak.ee (Postfix) with ESMTP id 2DBAA6105 for ; Fri, 27 May 2022 13:51:20 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at vm-hot-relay10.estpak.ee Received: from portal-smtp-out.hot.ee ([127.0.0.1]) by localhost (vm-hot-relay10.estpak.ee [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xMk-z+8c6EO1 for ; Fri, 27 May 2022 13:51:17 +0300 (EEST) Received: from mail.hot.ee (hot-relayhost3.estpak.ee [213.180.2.81]) by vm-hot-relay10.estpak.ee (Postfix) with ESMTP id 836C762D4 for ; Fri, 27 May 2022 13:51:17 +0300 (EEST) Content-Type: multipart/alternative; boundary="------------Lq0FoWLD0hqnhMSVnyDa24Is" Message-ID: <7a070729-d6c1-2db9-e70d-8a637aa9724a@hot.ee> Date: Fri, 27 May 2022 13:51:12 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Content-Language: et To: pgsql-general From: Andrus Subject: Determine if range list contains specified integer List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------Lq0FoWLD0hqnhMSVnyDa24Is Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi! Product type table contains product types. Some ids may missing :     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'); Property table contais comma separated list of types.     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' ); Type can specified as single integer, e.q 1,2,3 or as range like 6-9  or 23-44 List can contain both of them. How to all properties for given type. Query     select id     from artliik     join strings on ','||trim(strings.kirjeldLku)||',' like '%,'||trim(artliik.liiginrlki)||',%' returns date for single integer list only. How to change join so that type ranges in list like 6-9 are also returned? Eq. f list contains 6-9, Type 6,7,8 and 9 shoud included in report. Postgres 13 is used. Posted also in https://stackoverflow.com/questions/72404218/how-determine-if-range-list-contains-specified-integer Andrus. --------------Lq0FoWLD0hqnhMSVnyDa24Is Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Hi!


Product type table contains product types. Some ids may missing :

    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');

Property table contais comma separated list of types.

    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' );

Type can specified as single integer, e.q 1,2,3 or as range like 6-9  or 23-44
List can contain both of them.


How to all properties for given type.
Query

    select id
    from artliik
    join strings on ','||trim(strings.kirjeldLku)||',' like '%,'||trim(artliik.liiginrlki)||',%'

returns date for single integer list only.
How to change join so that type ranges in list like 6-9 are also returned?
Eq. f list contains 6-9, Type 6,7,8 and 9 shoud included in report.

Postgres 13 is used.

Posted also in

https://stackoverflow.com/questions/72404218/how-determine-if-range-list-contains-specified-integer

Andrus.

--------------Lq0FoWLD0hqnhMSVnyDa24Is--