1

Problem

Error running schema migration, err: cmd failed, cmd:
ALTER TABLE "schema"."table" ALTER COLUMN kill_id TYPE VARCHAR(MAX)
err: pq: ALTER TABLE ALTER COLUMN cannot run inside a transaction block

AWS Redshift does not support running the above ALTER COMMAND in an transaction block.

Does database/sql supports running sql commands without a transaction block?

How to run raw sql commands without a transaction block in Golang?

Alok Kumar Singh
  • 2,331
  • 3
  • 18
  • 37
  • https://stackoverflow.com/questions/53149484/error-alter-type-add-cannot-run-inside-a-transaction-block – LinPy Sep 16 '20 at 04:00
  • @LinPy not related. "ALTER TABLE "schema"."table" ALTER COLUMN kill_id TYPE VARCHAR(MAX)" command works in redshift. Need to do the same from golang. It can be done if run without a transaction. – Alok Kumar Singh Sep 16 '20 at 04:21
  • @AlokKumarSingh add the code how are you running this – Shubham Srivastava Sep 16 '20 at 05:28
  • this is also not working ALTER TABLE "schema"."table" ALTER COLUMN kill_id TYPE VARCHAR(MAX)", redshift does not support ALTER COLUMN on all column types, i would have to create a new table and migrate the table :( – Alok Kumar Singh Sep 16 '20 at 05:39
  • @ShubhamSrivastava the code was something like this https://github.com/Clever/s3-to-redshift/blob/master/redshift/redshift.go#L347-L357 – Alok Kumar Singh Sep 16 '20 at 05:41
  • 1
    Issue seems to be you are using *sql.Tx; dont do that use sql.DB – Shubham Srivastava Sep 16 '20 at 05:44
  • Thanks, i tried that. But the issue is Redshift does not allow such ALTER commands. https://stackoverflow.com/questions/17101918/alter-column-data-type-in-amazon-redshift – Alok Kumar Singh Sep 16 '20 at 05:44

0 Answers0