How to convert PostgreSQL array column to scalar column type

If your PostgreSQL database table contains “timestamp with time zone []” or “timestamp without time zone []” type columns and you want to convert them to “timestamp with time zone” or “timestamp without time zone” type, add the USING directive to the ALTER COLUMN command to tell PostgreSQL how to convert the array to the scalar value. In this example we will pick the first element of the array:

ALTER TABLE public.application
	ALTER COLUMN last_updated_date TYPE timestamp with time zone USING last_updated_date[0]

Leave a comment

Your email address will not be published. Required fields are marked *