Postgresql - Regex split csv line with potentials quotes
I would like to split a column that represent a csv line in postgres. Fields in this text line are delimited by pipe, sometime they are enclosed by quote and sometime not. In addition we can have escaped chars. field1|"field2"|field3|"22 \" lcd \| screen " Is there a regex to split this column (i.e. using regexp_split_to_array(....)? ) Abelisto Not about regexp but it works create or replace function split_csv( line text, delim_char char(1) = ',', quote_char char(1) = '"') returns setof text[] immutable language plpythonu as $$ import csv return csv.reader(line.splitlines(), quotechar=quote