-
Notifications
You must be signed in to change notification settings - Fork 296
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
Issues/Questions about Postgres array support #1077
base: master
Are you sure you want to change the base?
Conversation
cc @Vlix who initially added the Postgres array support, and @parsonsmatt who reviewed the PR also my co-workers @mitchellvitez and @danielbarter who were looking into this |
Ok, one more thing, it looks like Persistent wants to remigrate the columns each time? e.g. if you run this:
You will see those
This isn't explicitly tested for in these tests atm, but that would be a good one to add |
Thanks for reporting and exploring on this! |
Hey @MaxGabriel, I added in the PersistArray constructor to be able to correctly |
Ahhh, ok that is helpful info @Vlix. I saw @parsonsmatt closed the existing Postgres array issues (https://github.com/yesodweb/persistent/issues?q=is%3Aissue+postgres+array) —Matt may have thought it was considered solved? Or I just misunderstood |
@MaxGabriel I have not seen those issues. And yes, it seems like @parsonsmatt assumed I implemented arrays completely. I probably should have put big disclaimers around that constructor :/ I also see my JSON tests could have been written better. Apologies @ @parsonsmatt EDIT: This is all under the assumption that no one else added functionality for |
No worries @Vlix - your contributions are super welcome and I'd rather have something incomplete than wait for a perfection that never comes 😄 |
Fortunately we have a breaking change 2.11 coming out soon and then I want to get 3.0.0 out before too long, so we have two opportunities to implement breaking changes to behavior to provide extra functionality. |
Yes I want to second @parsonsmatt's thanks to you @Vlix. Postgres array support has been a requested feature for a long, long time so it was great you got it working for the JSON part of it. I just didn't realize that was what was intended |
Ok looked into this a little, small update on #1077 (comment) Currently we run this code to get data about columns:
The important part of the query is that it returns It looks like that table also has a Example:
|
I did a little investigation into postgresql-simple and came up with a way to support arrays of enums with it haskellari/postgresql-simple#57 This doesn't seem great though. persistent works through the edit: good solution on that issue would be to generate the cast with the enum values themselves, which seems pretty doable for persistent enums for example |
Hm, ok but even if inserts are solved, selects are still a problem. My understanding is: when custom types are used, they get assigned an OID by Postgres identifying their type. Persistent gets access to the OID like so:
Then it checks the OID against a handful of hard-coded options ( To get this additional data, Persistent can use getTypeInfo (or query Postgres itself). The results of that query are cached on a per-connection basis, which is helpful. ( Overall I think this could be a good move to use this, even though the caching behavior could be better. |
Hey all, we started trying to use the Postgres array support at work and ran into some issues. I'm not sure which of these are considered bugs, vs expected limitations.
Documentation on using
PersistArray
is pretty limited and we could probably improve that. Happy to PR this. Some notable things:The docs currently say "Intended especially for PostgreSQL backend for text arrays". I don't think this is true? They seem to work fine for
int[]
for example.Generally lacking a description of how to write
PersistField
orPersistFieldSql
instances for them.Serializing to
PersistArray
deserializes toPersistList
. This isn't a big deal, and I haven't looked into if there's a solution for it, but it would be great to document it if not! Seeinstance PersistField RoundtripTextArray
in the draft PR for an example of this failing.Edit: from the source, this is probably intended for backwards compatibility reasons and the best we can do is document it?
jsonb[]
column fails with the following error:Edit: This probably comes from https://www.postgresql.org/docs/9.1/sql-expressions.html#SQL-SYNTAX-ARRAY-CONSTRUCTORS