Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
REASY opened this issue Jun 29, 2021 · 5 comments
Open

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

REASY opened this issue Jun 29, 2021 · 5 comments
Labels
bug Something isn't working database Updates database drivers help wanted Extra attention is needed

Comments

@REASY
Copy link

REASY commented Jun 29, 2021

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
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:
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 3dfb0ff

  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 3dfb0ff

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

@Fontinalis Fontinalis added bug Something isn't working database Updates database drivers help wanted Extra attention is needed labels Sep 22, 2021
@dhui
Copy link
Member

dhui commented Sep 23, 2021

I don't know if there's a way to have multi-statment work with your migration. multistmt is naive and simply splits by ; so it's incorrectly separating the body of your function. Also, your migration only consists of a single statement so you don't need to use multi-statement

@ppapishe
Copy link

I am facing the same issue.
I am trying to run an anon block and getting the same error in multi-statement mode

DO $$
BEGIN
    EXECUTE 'set search_path TO ' || current_database() || ', public';
END;
$$;

Let me know if any one of you guys figured out a workaround

@ppapishe
Copy link

@dhui @Fontinalis , Please let me know if you plan to work on this ? else, Please give me a little direction on how to do this and I will try to push a commit. Thanks

@GrandFelix
Copy link

Why there is no option that we could use custom delimiter ? multiStmtDelimiter = []byte(";") could be anything right? Like ##__## and we could parse sql files properly so we don't split sql statement for every ; which is not ok in case of Postgres functions etc.

@th0th
Copy link

th0th commented Nov 25, 2023

Are there any updates on this one? Or did you folks manage to come up with a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working database Updates database drivers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants