-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
got XXXX parameters but the statement requires YY - potential BUG in 1.3.0 #690
Comments
Hello, I have experienced a similar issue where if a query string ends with a white space or a new line the result of this code is:
Version: 1.3.0, 1.3.1 Kind Regards |
@jmoiron It was not space problem, but found what is. if you have insert string like this: But since it is so common to end SQL queries with ; I think this is bug. Kind regards, |
I second what @drsasa said, removing the |
@jmoiron @hmgle See comment here. |
@drsasa , @ekrem95 Using one of the standard Postgres' upsert approaches like this: var addListingNamedSQL = "INSERT INTO listings (id, name, symbol) VALUES (:id, :name, :symbol) ON CONFLICT (id) DO UPDATE SET name = :name, symbol = :symbol" (tried to have the SQL in one single line, instead of the multi line form using backticks, just to remove any other possible issue) and then use it with // TEST
listings = []domain.Listing{
{Id: "1", Symbol: "1", Name: "1"},
{Id: "2", Symbol: "2", Name: "2"},
}
r.NamedExec(addListingNamedSQL, listings) it throws the error: The classic INSERT works just fine: INSERT INTO listings (id, name, symbol) VALUES (1, '1n', '1')
ON CONFLICT (id) DO UPDATE SET name = '1n', symbol = '1'; |
I think NamedExec do not support bulk UPSERT. INSERT INTO listings (id, name, symbol) VALUES ($1, $2, $3),($4, $5, $6) ON CONFLICT (id) DO UPDATE SET name = $7, symbol = $8 Which is not good interpretation of what you trying to do. So my conclusion is that UPSERT is not supported on batch insert. Cheers! |
From other hand just saw that your PG syntax is not good :) INSERT INTO listings (id, name, symbol) VALUES (1, '1n', '1')
ON CONFLICT (id) DO UPDATE SET name = excluded.name, symbol = excluded.symbol; Which take us to this: var addListingNamedSQL = "INSERT INTO listings (id, name, symbol) VALUES (:id, :name, :symbol) ON CONFLICT (id) DO UPDATE SET name = excluded.name, symbol = excluded.symbol" And everything will work as expected. So really nothing wrong here on Cheers! |
@drsasa Thanks for the detailed feedback, Alexandar! The SQL that I showed before it's just fine and it works without a problem. Meanwhile, to overcome this issue, I used the classical approach of doing all the "upserts" in a transaction. And the SQL used for this is: var addListingSQL = `INSERT INTO listings (id, name, symbol) VALUES ($1, $2, $3)
ON CONFLICT (id) DO UPDATE SET name = $2, symbol = $3` |
@dxps It is really safe to use Cheers! |
@drsasa True! I'll update that SQL and start using Thanks again! |
Hello,
Seems after upgrading to version 1.3.0 this do not work anymore:
I on my queries getting:
pq: got XXXX parameters but the statement requires YY
but YY is not 65535 it is number of columns, in above example would be YY=3.
This is since >=1.3.0 version, earlier versions everything works.
Best regards,
Alexandar
The text was updated successfully, but these errors were encountered: