-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[PostgreSQL] citext is not compatable with text #295
Comments
|
Other adaptors often to query the metadata on initial connection to discover these unstable OIDs. This will also come up if supporting Postgres |
Even though this is for a different driver in a different language, the query and |
Is there a workaround that I can do in my code to get
I've been digging through some github issues... can I use something like Not sure what else I need to do though? How do I tell sqlx that the "citext" type is to be treated the same way as regular "text" ? I'm pretty new to Rust. :) |
For sql to Rust, you can cast to text: ( |
Is there a way to tell sqlx how to deal with CITEXT globally, without needing to manually cast in all of the actual SQL queries individually? The |
Honestly I think we can just add a couple checks:
This technically isn't robust if someone adds a type named |
@abonander ...seems sensible to me! :) I'd be very surprised if there is even a single person out there anywhere who has not only created their own custom type named And even if they did exist... I don't see why everyone else should miss out on this simple fix due to them doing something pretty silly (and that they could change anyway, they could just use a different type name for example). And wouldn't sqlx already be broken for them anyway? But for everyone else using Otherwise you're dealing with having to look up the OID on every new connection... which is wasteful both in terms of the extra query... but more importantly all the extra effort writing more complex code to develop that feature... which will probably never happen (and really doesn't need to). But even then... wouldn't we just using the name "citext" to convert to an OID anyway? So what's the difference in the end given that sqlx can already go by name without the OID lookup query?
Depending on where this library is getting the postgres type name from, it might instead be named
...is what worked for me in terms of detecting |
We still have to do a lookup because all we get in the responses from the protocol is the type OID, but the connection will automatically resolve and cache unknown type OIDs. |
Ah right, fair enough. But yeah still sounds like a great solution to me. I'd really love to see this solved once and for all, as I'm having to do lots of workarounds and extra codegen right now. It's also less performant doing unnecessary casting in postgres for all inserts/updates/selects. I'd help out myself, but I'm still very new to Rust. Also I'm still a bit fuzzy on whether I can actually use Can I somehow use Thanks for all your efforts & consideration! |
Thanks. That was helpful! Is there a way to perform the cast without SQLx thinking a non nullable column is now nullable? |
In case anyone else is looking for an answer, you can force a column to be treated as NOT NULL: https://docs.rs/sqlx/0.5.2/sqlx/macro.query.html#force-not-null e.g. if column 'email' is of type CITEXT NOT NULL: r#"SELECT email::TEXT as "email!" FROM public.user"# |
Is there any way to fix this that doesn't involve copious hacks right now? I'd really like to just declare the type once and move on. Otherwise it makes using the Or alternatively, is there a PR I could submit to get this fixed in sqlx directly? |
Just came across this myself, too. Is anyone working on this? |
Also interested in this. |
This sounds like a good idea to me. Is there anyone working on this? |
query:
Where
email
iscitext
. As a workaround, the following cast is required to cause this not to error:However, sqlx should be able to handle citext natively.
The text was updated successfully, but these errors were encountered: