In most cases the SQLDelight <runtime parameter ty...
# squarelibraries
l
In most cases the SQLDelight runtime parameter type inference works great, but in instances where it's ambiguous is it possible to specify the type in the query? I'm running into this for the first time and can't figure out the syntax.
Here's a query I had that worked. It relies on PostgreSQL to generate a
TIMESTAMP
.
And here's how I'm trying to change it now. I'd like to pass it
java.time.Instant
to use as a
TIMESTAMP
.
It's way off on the type of the parameter, inferring it should be a
org.postgresql.util.PGInterval
. Maybe SQLDelight doesn't understand the context of the parameter well enough.
This was my best guess, based on the syntax used for custom column types but it doesn't seem to work that way.
h
Use sql cast
CAST(:now AS TIMESTAMP)
l
@hfhbd that works great for something like:
Copy code
AND sessionRecord.created_at = CAST(:now AS TIMESTAMP)
(in fact the CAST isn't necessary here) but in this case:
Copy code
AND sessionRecord.created_at > CAST(:now AS TIMESTAMP) - INTERVAL '28 days'
the resulting
now
parameter is still coming up as a
org.postgresql.util.PGInterval
.
h
Hm, this is definitely a bug. Explicitly casting the bind parameter should overwrite the implicit type.
l
Ahh! Thanks for helping me figure out it's a bug so I can stop trying to fix my syntax. I'll file an issue.
h
Thanks. But I mean, there is no special handling yet, but should be. What's the point to specify the type explicitly if it is ignored/overwritten by the compiler?
l
My goal isn't to specify the type, rather to build a query that takes a
java.time.Instant
and uses it as a
TIMESTAMP
within the above query. Specifying the type was just the latest thing I was trying along the way. I suppose I had assumed that would be the solution but I'm open to changing any syntax or approach you might suggest!
h
Yeah, I think so too. Could you paste your query here (or in an issue)? Then I will take a look. I guess the subtraction operation changes the type somehow.
l
You got it, and thanks. Almost done submitting the issue.
👍 1
@hfhbd were you able to take a look?
h
Yes, but I need to find a proper solution but I am on vacation now.
🍻 1
l
Awesome, thanks for taking a look and enjoy your vacation! 🏝️