Closed MaxGabriel closed 3 years ago
Create a newtype which would have an explicit cast, generate not just 'red'
but 'red' :: colour
. I.e. don't cast the array, but rather the enum already. I suspect you'll run into other ambiguities elsewhere as well.
An example:
# CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
# select array ['sad' :: mood, 'ok' :: mood];
array
----------
{sad,ok}
(1 row)
Seems reasonable, thanks @phadej
Hi, I looked into improving the persistent library to support JSON arrays in Postgres. Persistent uses PGArray, which I think needs a cast to support arrays of enums. Here's some example code:
PGArray uses the ARRAY syntax:
Which if you do that in SQL you get:
(Note that array literal syntax does work here)
Is the recommended way to insert arrays of enums to use
Many
to add in a cast after the array? This works:Which is the same as:
If so, would something like a
PGCastedArray
or something else be a good addition to the library?Alternatively I'd be happy to just document this approach in postgresql-simple.