lib / pq

Pure Go Postgres driver for database/sql
https://pkg.go.dev/github.com/lib/pq
MIT License
9.04k stars 909 forks source link

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

Closed SLYJason closed 3 years ago

SLYJason commented 3 years ago

Hi, I have migration file but failed to run and got:

pq: unterminated dollar-quoted string at or near "$$
BEGIN
    if not exists (SELECT safe_url_name, COUNT(*) FROM people_model.agents GROUP BY safe_url_name HAVING COUNT(*) > 1) x then

Here is my migrate up .sql:

-- +migrate Up
SET LOCAL statement_timeout = '15s';
DO $$
BEGIN
    if not exists (SELECT safe_url_name, COUNT(*) FROM people_model.agents GROUP BY safe_url_name HAVING COUNT(*) > 1) x then
        ALTER TABLE people_model.agents ADD CONSTRAINT "agents_safe_url_name_key5" UNIQUE ("safe_url_name");
    else
        RAISE NOTICE 'safe_url_name has duplicates';
    end if;
END $$;

Someone faced the same issue before, but I can not figure it out. Can someone give me some guidance?

SLYJason commented 3 years ago

I figured it out. Closed.