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
Question: Combining the concepts of Postgresql data types and Value List Parameters. #112
Comments
In order to make this work, you have to cast each value separately. The following example is from this SO post: https://stackoverflow.com/questions/51546003/casting-multiple-values-in-hugsql-or-yesql-with-postgres/51600434#51600434 You can generate a cast for each value in your vector in HugSQL by using a Clojure Expression:
Which will end up giving you something like this:
So, the above takes the values vector and uses HugSQL's deep-get syntax to pull in each of the values individually and add the type cast to each one. So, you're effectively building a new set of HugSQL parameters on the fly that looks like:
Hope that helps! |
Definitely helps and works! Though this does feel a bit more hands-on than I would expect. I'll see if I can make a PR that treats my naive syntax of |
…es of Postgres types.
I replied to the PR. My instinct here is to continue to not parse/decipher/validate any actual SQL and leave that to the database. I realize that this may be a common occurrence, but there are at least three work-arounds for this--none of which seem too painful or hands-on.
|
Works for me! |
For a toy example consider I have an SQL table fish. One of the columns of fish is scaleColor where the value can be a member of an enumeration defined as
I would like to fetch all the fish where the color is 'blue' or 'red'. My naive hugsql query would look like,
Executing this clojure code will throw the error
ERROR: operator does not exist: color = character varying
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
My questions are;
I tried also making use of SQL
CAST
but couldn't find a way to make it work with my list.The text was updated successfully, but these errors were encountered: