postgresql - Split a string in characters SQL -
how can split string in characters , add new line after each character in postgresql
for example
num desc 1 hello 2 bye num desc 1 h e l l o 2 b y e
select num, regexp_split_to_table(descr,'') the_table order num;
sqlfiddle: http://sqlfiddle.com/#!15/13c00/4
the order of characters not guaranteed , achieving bit complicated.
building on erwin's answer regarding problem:
select case when row_number() on (partition id order rn) = 1 id else null end id_display, ch_arr[rn] ( select *, generate_subscripts(ch_arr, 1) rn ( select id, regexp_split_to_array(descr,'') ch_arr data ) t1 ) t2 order id, rn;
edit:
if want single string each id, characters separated newline, can use this:
select id, array_to_string(regexp_split_to_array(descr,''), chr(10)) data order id
Comments
Post a Comment