How do I recast the entire column/all rows of data with Postgres type integer[]
arrays inside of them to type integer
?
Below, user_email_id is type integer[]
\d emails
Column | Type
---------------+------------------------
id | integer
user_id | integer
user_email_id | integer[]
SELECT id, user_id, user_email_id FROM emails;
id | user_id | user_email_id
----+---------+---------------
65 | 1 | {98,110}
66 | 1 | {99}
For the row with user_email_id={99}, this works:
ALTER table emails
ALTER COLUMN user_email_id type integer
USING user_email_id[1]::INTEGER;
Expected output for id=66;
\d emails
Column | Type
---------------+------------------------
id | integer
user_id | integer
user_email_id | integer
SELECT id, user_id, user_email_id FROM emails where id=66;
id | user_id | user_email_id
----+---------+---------------
66 | 1 | 99
But what would one do where there are two values inside the array {98,110}
? In this case, I guess I'd either have to cast to a string, or have to create two rows for the record where id=65;?