0

Example Table:

CREATE TABLE example_table (
    example_column TEXT,
)

Example Record (json stored as text):

INSERT INTO example_table VALUES ('{"value": "1.3", "Type": "float"}')

Goal is to:

  1. Update column type to Double Precision
  2. Update the value to be 1.3

I know the following is close to what I want, but I can't find the correct syntax.

ALTER TABLE example_table ALTER COLUMN example_column DOUBLE PRECISION...missing parse syntax
user2263572
  • 5,435
  • 5
  • 35
  • 57

1 Answers1

1

You can specify a using clause to define the conversion:

alter table example_table
   alter example_column 
      type double precision using (example_column::jsonb ->> 'value')::double precision