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

Dodaj komentarz

avatar
  Subscribe  
Powiadom o