we updated our database up to version 13 and tried to use the latest version of diesel_ltree (0.2.6).
We discovered that we couldn't insert objects with ltree into the database. We receivied an error from postgres stating:
"2022-05-23 15:34:19.036 UTC [256] ERROR: unsupported ltree version number 52".
After digging into the postgres code we found this function: ltree_recv().
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
int version = pq_getmsgint(buf, 1);
char *str;
int nbytes;
lquery *res;
if (version != 1)
elog(ERROR, "unsupported lquery version number %d", version);
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
res = parse_lquery(str);
pfree(str);
PG_RETURN_POINTER(res);
}
That shows that you need to add a version before receiving the actual message.
So we added an version to your ToSql function:
impl diesel::serialize::ToSql<crate::sql_types::Ltree, Pg> for Ltree {
fn to_sql<W: std::io::Write>(
&self,
out: &mut diesel::serialize::Output<W, Pg>,
) ->
diesel::serialize::Result {
let version_number: [u8;1] = [1];
let msg = [&version_number, self.0.as_bytes()].concat();
out.write_all(&msg)?;
Ok(diesel::serialize::IsNull::No)
}
That seems to work for us, but we are unsure if that is a stable solution.
Can you confirm that this change doesnt break anything else and if it is stable create an updated version of it?
Best Regards
Xanvu