-
Notifications
You must be signed in to change notification settings - Fork 796
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
How to get the "RETURNING" data in "INSERT"? #411
Comments
Run it with |
@jackc This doesn't seem to work. I'm getting an error "Scan received the wrong number of arguments, got 12 but expected 1" |
Hem. It seems that the pgx doesn't like it when the RETURNING is written as |
Those two commands mean different things. The first error you got with pgx was because PostgreSQL returned a one column results set where you expected 12 columns. See example below:
|
Thanks for the explanation @jackc I did figure it out. That's why I've written the 2nd post. |
Well, it is supported, though I'm not sure when it would make sense to actually use it that way. You can scan into a single You could do something like: var row pgtype.Record
err := conn.QueryRow("insert ... returning (...)").Scan(&row) There are a few limitation though. First, due to how PostgreSQL represents record types it will only work using the binary format. This is what pgx uses by default but if you were also forcing the text format for some reason (e.g. to reduce round trips to PG server) then row types are not readable. Secondly, you lose the names of the columns and have to access the data positionally. Third, you lose the ability to scan the record fields into specific or custom types. So you can do it, but I think it would only make sense in rare circumstances. |
How to get the "RETURNING" data in "INSERT",such as:
The text was updated successfully, but these errors were encountered: