Skip to content

Cannot execute multiple statements with sql.file #86

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

Closed
nikku opened this issue Jun 23, 2020 · 1 comment
Closed

Cannot execute multiple statements with sql.file #86

nikku opened this issue Jun 23, 2020 · 1 comment

Comments

@nikku
Copy link

nikku commented Jun 23, 2020

Likely related to #76 my intuitive notion of sql.file was that I am able to execute arbitrary SQL files. However, at the moment it looks like postgress will attempt to wrap everything in a prepared statement that does not support more than one statement?

Example create.sql file:

CREATE TABLE foo (
  id numeric
);

CREATE TABLE bar (
  id numeric
);

Executing this one fails on the postgres side with:

PostgresError: cannot insert multiple commands into a prepared statement

I'm on v2.0.0-beta.0 but the issue exists on v1.0.0, too.

@porsager
Copy link
Owner

porsager commented Aug 3, 2020

The query will be executed as a simple query if you don't pass a second argument to sql.file().

The postgres protocol doesn't allow passing parameters in simple queries so you can't have multiple statements in the same file while also using positional parameters.

I would think that if you get the above error it is because you run it like this:

sql.file('create.sql', [])

Try removing any arguments but the filename and run it like this:

sql.file('create.sql')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants