Input parameters not taking nullability into consideration #23
Replies: 5 comments
-
Ah that's interesting, I need to look a bit into it! There probably is a way to tell if a field in an insert/update query is a nullable column 🤔 |
Beta Was this translation helpful? Give feedback.
-
Doing a little searching, it seems like the query itself can't tell you anything about the nullability, but you can query the schema and get that info SELECT column_name, is_nullable
FROM information_schema.columns
WHERE table_name = 'my_table'
AND column_name = 'my_nullable_field'; column_name | is_nullable
------------------|-------------
my_nullable_field| YES
|
Beta Was this translation helpful? Give feedback.
-
Unfortunately I cannot really use that to implement this because So I'm not sure this can actually be implemented, I'll have to look more into how sqlx does it (if it actually does it at all) |
Beta Was this translation helpful? Give feedback.
-
I believe sqlx runs an explain query to get nullability:
https://github.com/launchbadge/sqlx/blob/main/FAQ.md#how-do-the-query-macros-work-under-the-hood |
Beta Was this translation helpful? Give feedback.
-
So I'm turning this into a discussion since I believe there's no way to tell if a query parameter is bound to a nullable column (not even by looking at the query explanation).
Louis pointed out we could first ask the Postrgres folks if such an API to solve our problem could be added, that would for sure be the best possible outcome! I think I'll reach out soon and see how that goes |
Beta Was this translation helpful? Give feedback.
-
I have an update statement that sets a nullable text field:
But the generated function from squirrel doesn't take into consideration the nullable field and requires me to pass in a
String
instead of anOption(String)
I'm not sure if there is any way to hint to squirrel that this should be nullable or not
Beta Was this translation helpful? Give feedback.
All reactions