2 deleted 49 characters in body
source | link
create table tbl (val text);
insert into tbl values 
('0,11.2,2,5,1-2,1,SAMPLE CLOT,'',11.2 g/dl,14300,145,negative'),
('9,11.2,2,5,1-2,1,SAMPLE CLOT,'',11.2 g/dl,14300,145,negative'),
('3,11.2,2,5,1-2,1,SAMPLE CLOT,'',11.2 g/dl,14300,145,negative'),
('8,11.2,2,5,1-2,1,SAMPLE CLOT,'',11.2 g/dl,14300,145,negative');

You can get first element of the list using regexp_split_to_array()string_to_array() function.

select (regexp_split_to_arraystring_to_array(val, ','))[1] from   tbl
| regexp_split_to_arraystring_to_array |
| :-------------------- |
| 0                     |
| 9                     |
| 3                     |
| 8                     |

Or filter rows using a cast in this way:

(regexp_split_to_arraystring_to_array(val, ','))[1]::int < 7
select *
from   tbl
where  (regexp_split_to_arraystring_to_array(val, ','))[1]::int < 7
| val                                                         |
| :---------------------------------------------------------- |
| 0,11.2,2,5,1-2,1,SAMPLE CLOT,',11.2 g/dl,14300,145,negative |
| 3,11.2,2,5,1-2,1,SAMPLE CLOT,',11.2 g/dl,14300,145,negative |

db<>fiddle heredb<>fiddle here

create table tbl (val text);
insert into tbl values 
('0,11.2,2,5,1-2,1,SAMPLE CLOT,'',11.2 g/dl,14300,145,negative'),
('9,11.2,2,5,1-2,1,SAMPLE CLOT,'',11.2 g/dl,14300,145,negative'),
('3,11.2,2,5,1-2,1,SAMPLE CLOT,'',11.2 g/dl,14300,145,negative'),
('8,11.2,2,5,1-2,1,SAMPLE CLOT,'',11.2 g/dl,14300,145,negative');

You can get first element of the list using regexp_split_to_array() function.

select (regexp_split_to_array(val, ','))[1] from   tbl
| regexp_split_to_array |
| :-------------------- |
| 0                     |
| 9                     |
| 3                     |
| 8                     |

Or filter rows using a cast in this way:

(regexp_split_to_array(val, ','))[1]::int < 7
select *
from   tbl
where  (regexp_split_to_array(val, ','))[1]::int < 7
| val                                                         |
| :---------------------------------------------------------- |
| 0,11.2,2,5,1-2,1,SAMPLE CLOT,',11.2 g/dl,14300,145,negative |
| 3,11.2,2,5,1-2,1,SAMPLE CLOT,',11.2 g/dl,14300,145,negative |

db<>fiddle here

create table tbl (val text);
insert into tbl values 
('0,11.2,2,5,1-2,1,SAMPLE CLOT,'',11.2 g/dl,14300,145,negative'),
('9,11.2,2,5,1-2,1,SAMPLE CLOT,'',11.2 g/dl,14300,145,negative'),
('3,11.2,2,5,1-2,1,SAMPLE CLOT,'',11.2 g/dl,14300,145,negative'),
('8,11.2,2,5,1-2,1,SAMPLE CLOT,'',11.2 g/dl,14300,145,negative');

You can get first element of the list using string_to_array() function.

select (string_to_array(val, ','))[1] from   tbl
| string_to_array |
| :-------------- |
| 0               |
| 9               |
| 3               |
| 8               |

Or filter rows using a cast in this way:

(string_to_array(val, ','))[1]::int < 7
select *
from   tbl
where  (string_to_array(val, ','))[1]::int < 7
| val                                                         |
| :---------------------------------------------------------- |
| 0,11.2,2,5,1-2,1,SAMPLE CLOT,',11.2 g/dl,14300,145,negative |
| 3,11.2,2,5,1-2,1,SAMPLE CLOT,',11.2 g/dl,14300,145,negative |

db<>fiddle here

1
source | link

create table tbl (val text);
insert into tbl values 
('0,11.2,2,5,1-2,1,SAMPLE CLOT,'',11.2 g/dl,14300,145,negative'),
('9,11.2,2,5,1-2,1,SAMPLE CLOT,'',11.2 g/dl,14300,145,negative'),
('3,11.2,2,5,1-2,1,SAMPLE CLOT,'',11.2 g/dl,14300,145,negative'),
('8,11.2,2,5,1-2,1,SAMPLE CLOT,'',11.2 g/dl,14300,145,negative');

You can get first element of the list using regexp_split_to_array() function.

select (regexp_split_to_array(val, ','))[1] from   tbl
| regexp_split_to_array |
| :-------------------- |
| 0                     |
| 9                     |
| 3                     |
| 8                     |

Or filter rows using a cast in this way:

(regexp_split_to_array(val, ','))[1]::int < 7
select *
from   tbl
where  (regexp_split_to_array(val, ','))[1]::int < 7
| val                                                         |
| :---------------------------------------------------------- |
| 0,11.2,2,5,1-2,1,SAMPLE CLOT,',11.2 g/dl,14300,145,negative |
| 3,11.2,2,5,1-2,1,SAMPLE CLOT,',11.2 g/dl,14300,145,negative |

db<>fiddle here