exebook
exebook

Reputation: 33900

Convert a Json-in-TEXT column to a real JSONB column

I have a TEXT column that actually contains a stringized JSON. Now I just want to convert it to a real JSONB. How to do this from psql console?

Upvotes: 2

Views: 39

Answers (1)

S-Man
S-Man

Reputation: 23676

If all data is valid JSON, then this should work:

demo:db<>fiddle

ALTER TABLE mytable ALTER COLUMN mytext_col TYPE jsonb USING mytext_col::jsonb;

Upvotes: 2

Related Questions