pq: unterminated dollar-quoted string at or near "$BODY$
Seems like x-multi-statement=true is causing migrate to fail with error: migration failed: unterminated dollar-quoted string at or near "$BODY$
Steps to Reproduce
- My migrations look like
CREATE OR REPLACE FUNCTION add_column(target REGCLASS)
RETURNS VOID AS $BODY$
DECLARE
table_name TEXT := QUOTE_IDENT(target :: TEXT);
BEGIN
EXECUTE 'ALTER TABLE ' || table_name ||
' ADD COLUMN IF NOT EXISTS col_id INT4 NOT NULL';
END;
$BODY$
LANGUAGE plpgsql;- I ran migrate with the following options, please note x-multi-statement=true:
docker run -v /tmp/migrations:/migrations --network host -i 9df23b0b252d -path /migrations/ -database 'postgres://postgres:@localhost:5433/test?sslmode=disable&x-multi-statement=true' up9df23b0b252d is an image id built at commit https://github.com/golang-migrate/migrate/commit/3dfb0ff538aaebd744c6b8145ee7581f06c7a9ed
- See error
error: migration failed: unterminated dollar-quoted string at or near "$BODY$
Migrate Version 4.14.1-43-g3dfb0ff, running it as docker container built at commit https://github.com/golang-migrate/migrate/commit/3dfb0ff538aaebd744c6b8145ee7581f06c7a9ed
Loaded Source Drivers godoc-vfs, gcs, file, s3, github, github-ee, gitlab, go-bindata, bitbucket
Loaded Database Drivers postgres, clickhouse, cockroachdb, firebird, mongodb, mongodb+srv, sqlserver, postgresql, stub, crdb-postgres, mysql, neo4j, pgx, redshift, spanner, cassandra, cockroach, firebirdsql
In case if I run the migration without x-multi-statement=true it works fine:

Also I can create that function via psql without any issue:

Attachments: migrations.zip
Source: golang-migrate/migrate