According to the goose documentation, complex statements that include semicolons must be annotated with -- +goose StatementBegin
and -- +goose StatementEnd
Your statement contains semicolons embedded within it so you need to use these annotations. Otherwise goose mangles the SQL so that libpq gives errors.