Search code examples
jsonpostgresqlddljsonb

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?


Solution

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