Kindly help to modify a column of type integer to integer array:
I had created a table with a column content_id
of type integer. then I tried to change the content_id(integer)
to integer[](integer array)
but its showing error as displayed:
TestDatabase=# ALTER TABLE tbl_handset_content ALTER COLUMN content_id TYPE integer[];
ERROR: column "content_id" cannot be cast to type "pg_catalog.int4[]"
Regards,
Sravan
First, specify the name of the table to which the column you want to change belongs in the ALTER TABLE clause. Second, give the name of column whose data type will be changed in the ALTER COLUMN clause. Third, provide the new data type for the column after the TYPE keyword.
The syntax to modify a column in a table in PostgreSQL (using the ALTER TABLE statement) is: ALTER TABLE table_name ALTER COLUMN column_name TYPE column_definition; table_name. The name of the table to modify.
You must own the type to use ALTER TYPE . To change the schema of a type, you must also have CREATE privilege on the new schema. To alter the owner, you must also be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the type's schema.
Use the :: operator to convert strings containing numeric values to the DECIMAL data type. In our example, we converted the string ' 5800.79 ' to 5800.79 (a DECIMAL value). This operator is used to convert between different data types. It's very popular within PostgreSQL.
Try this (column test_id is of type INTEGER before alter takes place). PostgreSQL 8.4.
ALTER TABLE test.test_id
ALTER COLUMN test_id TYPE INTEGER[]
USING array[test_id]::INTEGER[];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With