-
-
Notifications
You must be signed in to change notification settings - Fork 249
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
VARCHAR[]
cannot be extracted as Rust Vec<String>
#1793
Comments
Put up a PR with a unit test or two and lets see what CI says. In general, this looks like a good change. AFAIK, the structure of an ArrayType doesn't change based on its element type. |
Reusing the |
So no, we have to figure out something different. |
I was probably a little imprecise. What I mean is that an ArrayType will have the same shape as ArrayType so long as E and E2 are themselves binary compatible. And yeah, I now see here in that diff that it's using our |
I'm not aware of such a function, but I believe that you are referring to the answer of "binary coercible", and that is the question that is answered by |
It's discussed a bit in https://www.postgresql.org/docs/current/sql-createcast.html |
Yeah, digging through the postgres sources, I guess we'd need to do something like lookup both types in the EDIT: Actually, I'm not sure what we'd check. I'm not seeing anything in the Postgres sources that check for "array binary compatibility" -- at least not in the obvious places. |
hmm. Maybe it's a combination of EDIT: Maybe that's not enough either. |
We're gonna have to handroll it if we want it. It will be easy enough to write something that only works in a reasonable number of cases and doesn't work in all cases, and that will probably be fine. |
My goal actually is to be able to represent different Postgres string in Rust and convert them back correctly, without losing the actual type, to Postgres types. Representing different Postgres strings via a single Rust struct #[derive(Debug)]
pub(crate) struct Varchar(pub(crate) String);
impl IntoDatum for Varchar {
fn into_datum(self) -> Option<pg_sys::Datum> {
self.0.into_datum()
}
fn type_oid() -> pg_sys::Oid {
VARCHAROID
}
}
impl FromDatum for Varchar {
unsafe fn from_polymorphic_datum(
datum: pg_sys::Datum,
is_null: bool,
typoid: pg_sys::Oid,
) -> Option<Self>
where
Self: Sized,
{
let val = String::from_polymorphic_datum(datum, is_null, typoid);
val.and_then(|val| Some(Self(val)))
}
} This way I can differentiate between different |
Can you explain why you wish to preserve these types? |
Data migration purposes. I serialize tuples in Postgres tables into a different data format and deserialize the format back into PG tuples. |
When I check the
is_compatible_with
function forString
, we also checkVARCHAROID
. This way, we can mapTEXT
+VARCHAR
datums to RustString
.But it is not the case with
VARCHAR[]
. I getnon-binary coercible types
error when I try to extractVec<String>
fromVARCHAR[]
datum. I believe we lack a similar check atis_compatible_with
forVec<T>
.I wonder might my very naive approach below work out. It basically relies on if element types are compatible.
Looks like a related discussion. #1361
The text was updated successfully, but these errors were encountered: