Trying to convert a text field to a JSON field in Postgres. The field was an IPv6 address those having multiple semicolons e.g.: “14:eth1:vTA1:::4:”
Trying to run smth like:
ALTER TABLE data ALTER COLUMN ipv6 TYPE jsonb USING ipv6::jsonb;
Results in:
Failed to convert text field to JSON. Details: invalid input syntax for type json DETAIL: Expected end of input, but found “:”.
Any clues how to do it properly?
Advertisement
Answer
Use to_jsonb rather than ::jsonb.
ALTER TABLE data ALTER COLUMN ipv6 TYPE jsonb USING to_jsonb(ipv6);