Allow for USING keyword in ALTER COLUMN migrations. #21

Closed
opened 2018-07-09 07:03:37 +00:00 by jamie · 1 comment
jamie commented 2018-07-09 07:03:37 +00:00 (Migrated from git.hazaar.io)

This is not something that will be in a snapshot. But if you want to write your own migration script you should be able to supply a way of converting the existing column data.

For example, my current issue is converting a text column into a jsonb column. The column data contains mostly JSON strings, but also some numeric and plain text data. The below ALTER COLUMN query sorts everything out but there is no way to specify USING in current migration scripts.

ALTER TABLE public.request_data
    ALTER COLUMN content SET DATA TYPE jsonb 
		USING (CASE WHEN (content ~ '^([0-9]+[.]?[0-9]*|[.][0-9]+)$') != TRUE AND substring(content from 1 for 1) != '{' THEN '"' || content || '"' ELSE content END)::jsonb
This is not something that will be in a snapshot. But if you want to write your own migration script you should be able to supply a way of converting the existing column data. For example, my current issue is converting a `text` column into a `jsonb` column. The column data contains mostly JSON strings, but also some numeric and plain text data. The below `ALTER COLUMN` query sorts everything out but there is no way to specify `USING` in current migration scripts. ```sql ALTER TABLE public.request_data ALTER COLUMN content SET DATA TYPE jsonb USING (CASE WHEN (content ~ '^([0-9]+[.]?[0-9]*|[.][0-9]+)$') != TRUE AND substring(content from 1 for 1) != '{' THEN '"' || content || '"' ELSE content END)::jsonb ```
jamie commented 2018-07-10 00:55:34 +00:00 (Migrated from git.hazaar.io)

closed via commit 41752bfe19

closed via commit 41752bfe192e1bf55ce4ab72a9ac4d592afa6ecc
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: hazaar/hazaar-dbi#21
No description provided.