A value None : Option<T> is bound to a query, and that query executed.
The same query is later executed with a value Some(t: T) : Option<T>.
Since queries are cached by default, the type of value considered for the bound parameter is Option::<i32>::None.
This will raise a Postgres error on the second execution "incorrect binary data format in bind parameter <n>".
The fix consists in storing the value type of null values (using the result of the encode function to determine if the value is null), and then using a None value with the correct type (for example Option::<String>::None to persist a nullable TEXT value).
I am quite new to the sqlx library and there might be a better implementation but this one seems to be quite consistent with the implementation for the MySQL driver.
This PR fixes an issue occurring when:
None : Option<T>
is bound to a query, and that query executed.Some(t: T) : Option<T>
.Since queries are cached by default, the type of value considered for the bound parameter is
Option::<i32>::None
. This will raise a Postgres error on the second execution"incorrect binary data format in bind parameter <n>"
.The fix consists in storing the value type of null values (using the result of the
encode
function to determine if the value is null), and then using aNone
value with the correct type (for exampleOption::<String>::None
to persist a nullableTEXT
value).I am quite new to the
sqlx
library and there might be a better implementation but this one seems to be quite consistent with the implementation for theMySQL
driver.