15 lut 2016

Zmiana typlu pola character varying i użycie opcji USING

Dodanie pola do tabeli:

ALTER TABLE posts ALTER COLUMN post_tags TYPE character varying[]
USING CASE WHEN post_tags IS null THEN null ELSE string_to_array(post_tags, ', ') END;

select post_tags, string_to_array(post_tags, ',') from posts where 
post_tags is not null limit 5;
-- split_part(post_tags, ',', 2);