Open galileo-pkm opened 5 years ago
@galileo-pkm Yes, in your plain SQL you tell PostgreSQL the data type of the parameters: PREPARE test1 (int, SMALLINT)
. To emulate the way this works from the driver, change this to PREPARE test1 (unknown, unknown)
or simply PREPARE test1
.
As you've found, adding casts is the way to address this.
So the driver always runs prepared statements with "unknown" type, it does not matter that it knows the parameter type? I guess I just presumed that it passes the type. Maybe an update to the docs is a good idea?
This works (as expected)
Same query in go:
Gives this error:
If I change the last part to: "AND si.item_id = $2::integer" or to: AND si.item_id = $3 and run a query like this: db.Query(query, vID, iID, iID) The error is gone. vID is int32, iID is int16 if that matters.
As if the $2 is permanently cast into a string (text)? Anyone has any ideas what might cause this?
This is with /lib/pq v1.1.1 and postgresql 11.3
Sorry for the verbatim SQL, didn't have the time to construct a proper test.