#590·migrate

pq: unterminated dollar-quoted string at or near "$BODY$

Author: REASYCreated Jun 29, 2021Updated Jul 28, 2026
Labelsbughelp wanteddatabase

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

  1. My migrations look like
sql
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;
  1. I ran migrate with the following options, please note x-multi-statement=true:
bash
docker run -v /tmp/migrations:/migrations --network host -i 9df23b0b252d -path /migrations/ -database 'postgres://postgres:@localhost:5433/test?sslmode=disable&x-multi-statement=true' up

9df23b0b252d is an image id built at commit https://github.com/golang-migrate/migrate/commit/3dfb0ff538aaebd744c6b8145ee7581f06c7a9ed

  1. See error error: migration failed: unterminated dollar-quoted string at or near "$BODY$ image

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: image

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

Attachments: migrations.zip