You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes PostgreSQL gets confused about types if there's no explicit typing; I've noticed it with a non-empty array (PGArray) of enum elements, which gets recognized as text[] instead of user_role[] in my case. Setting types in queries explicitly is a bit cumbersome in some cases, and it would be handy if postgresql-simple facilitated it. For instance, the following works, but it uses Plain for something other than its intended purpose as it's described in the documentation (that is, it's a hack):
instanceToFieldRolewhere
toField r =Many [Escape$BS8.pack $show r, Plain":: user_role"]
Maybe something like a Typed Action String action constructor should be introduced, or the Plain description should be adjusted. It may be out of scope of postgresql-simple, but seems like ToField is the appropriate place for adding type information.
The text was updated successfully, but these errors were encountered:
Yes, I absolutely do want to implement something like this. However, my circumstances have changed, and I haven't been working on postgresql-simple for some time now; though I do plan on returning to this project someday. I really should bear down and get a simpler new release finished in the meantime, though.
Personally, I don't think this instance is that terrible of a hack. And, something along these lines may be necessary for implementing protocol-level parameters, as every such parameter is tagged with a type oid. I haven't investigated all the issues surrounding this, but I would imagine that picking the right type oid is far more critical for binary protocol-level parameters than it is for textual protocol-level parameters.
Oh, I would point out you can already create something like this more generically (and more robustly):
data TypeAnnotation a = TypeAnnotation a QualifiedIdentifier
instance ToField a => ToField (TypeAnnotation a) where
toField (TypeAnnotation x t) = Many [toField x, Plain " :: ", toField t]
I'm not sure if I've ever actually used this definition, though I know it's occurred to me several times. That doesn't really address the issue of how to come up with the QualifiedIdentifier automatically, though, which is sometimes nice or perhaps even necessary.
Sometimes PostgreSQL gets confused about types if there's no explicit typing; I've noticed it with a non-empty array (
PGArray
) of enum elements, which gets recognized astext[]
instead ofuser_role[]
in my case. Setting types in queries explicitly is a bit cumbersome in some cases, and it would be handy ifpostgresql-simple
facilitated it. For instance, the following works, but it usesPlain
for something other than its intended purpose as it's described in the documentation (that is, it's a hack):Maybe something like a
Typed Action String
action constructor should be introduced, or thePlain
description should be adjusted. It may be out of scope ofpostgresql-simple
, but seems like ToField is the appropriate place for adding type information.The text was updated successfully, but these errors were encountered: