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

Reuse of named prepared query within transaction causes error #36

Closed
pixelglow opened this issue Jul 12, 2011 · 1 comment
Closed

Reuse of named prepared query within transaction causes error #36

pixelglow opened this issue Jul 12, 2011 · 1 comment

Comments

@pixelglow
Copy link

If you have an outstanding transaction and you reuse a named, prepared query, this causes an error.

client.connect();
client.query("BEGIN"); \\ 1
for (var i = 0; i < 2; ++i)
    client.query({name: "X", text: "SELECT $1::INTEGER", values:[0]}, function (err, result) { if (err) console.log(err); });
client.query("COMMIT"); \\ 2
client.on("drain", function() { console.log("finished"); client.end(); });

The above code errors with:

{ length: 78,
  name: 'error',
  severity: 'ERROR',
  code: '42P03',
  message: 'cursor "X" already exists',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  file: 'portalmem.c',
  line: '207',
  routine: 'CreatePortal' }

To fix the error, remove the lines comment as 1 and 2 i.e. remove the surrounding transaction, and all will be fine. Also you can change the loop to go through only once, or remove the query name, to fix the bug.

This is a fairly typical idiom, where you open a transaction so that you can pipeline several INSERT's into it. Having the INSERT statement prepared helps tremendously with this sort of situation.

@brianc
Copy link
Owner

brianc commented Jul 13, 2011

awesome bug report. fixed & released new version.

p.s. in the future feel free to fork & write a failing test & submit pull request.

@brianc brianc closed this as completed Jul 13, 2011
brianc pushed a commit that referenced this issue Dec 20, 2019
brianc pushed a commit that referenced this issue Apr 28, 2020
Include documentation on the URL format in the README
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