-
Notifications
You must be signed in to change notification settings - Fork 916
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: unexpected Parse response 'D' #635
Comments
This is a bug. Which commit were you running? We just added something similar to this in the most recent commit (dd1fe20). |
I'm running 8837942. |
What I was trying to do, by the way, was read the rows of a Query and, while processing each one, insert a corresponding row to a different table; all of this within the same transaction. Of course I should have realized that's not legal. It's too bad, though; I really don't want to cache all of the data in memory, because there's a lot of it. But I can't think of a better answer. |
@rothskeller you can probably do what you're after using cursors: https://www.postgresql.org/docs/current/static/plpgsql-cursors.html |
Bless you, @tamird, that's exactly what I need. Learn something new every day.... |
Example on using cursors for your case (with some random data): if _, err := tx.Exec(`
DECLARE orders_cursor CURSOR FOR
SELECT id
FROM order
WHERE client_id = $1
ORDER BY createdAt
FOR UPDATE
`,
client.ID,
); err != nil {
return err
}
defer tx.Exec("CLOSE orders_cursor")
var id int64
for {
if err := tx.QueryRow(
`FETCH NEXT FROM orders_cursor`,
).Scan(&id); err != nil {
if err == sql.ErrNoRows {
// End of rows.
break
}
return err
}
if _, err := tx.Exec(`
UPDATE order
SET amount = amount - 1
WHERE CURRENT OF orders_cursor
`,
); err != nil {
return err
}
}
return nil |
Thanks for the example code @hypnoglow.
It works in the official libpq (and so all drivers that build on it or emulate it closely) because libpq defaults to fetching and buffering all the rows in memory. It's arguably a cheat but a very effectively one that's very widely used. See also #81. |
…ous query cursor is not yet closed. Problem only happen when the queries are run in the same transaction, we don’t have db transaction in v1 schema create handler. So only apply this fix to next. Related issue: lib/pq#635
…ous query cursor is not yet closed. Problem only happen when the queries are run in the same transaction, we don’t have db transaction in v1 schema create handler. So only apply this fix to next. Related issue: lib/pq#635
…ous query cursor is not yet closed. Problem only happen when the queries are run in the same transaction, we don’t have db transaction in v1 schema create handler. So only apply this fix to next. Related issue: lib/pq#635
This commit adds `Synchronized` flag to `support/db.Session`. When set to `true` and `Session` runs a transaction all `Exec*` and `Select*` methods are protected by mutex what allows running them in multiple goroutines. This is an experimental feature (see below) and not a breaking change (default is `false`). Postgres protocol does not allow sending Exec query results if previously sent Query haven't been fully read. This issue manifested itself when a PR that's sending read and write queries in multiple goroutines was merged. More info: lib/pq#81 lib/pq#635 Known limitations: * It's possible that it will not be needed if we decide to remove concurrency from ingestion pipeline (see #1983). We are adding this to unblock development of new ingestion processors with a more readable code (currently all database processors are merged into one big processor that is hard to read and test). Splitting `DatabaseProcessor` will be done in a separate PR/PRs. * During Horizon Team meeting we agreed to create a new `SynchronizedSession` struct embedding `db.Session` inside that would not be placed in a shared `support` package. The problem is that `history.Q` embeds `db.Session` inside. Changing this to `db.SessionInterface` requires updating a lot of files that create `history.Q` objects, tests and mocks. Given that we may want to revert this change in the future, the change in this commit seems to be simpler.
Is there anyone alive to fix it? @bartekn can you please have a deeper look into this? |
What's there to fix? |
I want to run 5 concurrent select query using a single transaction using libraries like github.com/jackc/pgx is working without any issue. But Can we please safely handle this without confusing with memory? |
lib/pq isn't well maintained and I'm not sure anyone here will fix this problem. You'll probably need to either write that PR yourself, or use pgx (I recommend using pgx). |
> I'm adding this issue for future people searching for it. Future people thank you! |
still not fixed, can confirm |
still not fixed, can confirm |
1 similar comment
still not fixed, can confirm |
You can probably close this issue immediately; it was user error on my part. But I searched your issues list looking for help debugging it and couldn't find any, so I'm adding this issue for future people searching for it.
In my case, this wonderfully cryptic message resulted from trying to start a new statement before reading all of the rows of the preceding statement. Should the future searcher get this error, that would be the first thing to look for.
The text was updated successfully, but these errors were encountered: