How to specify type using sql template
I'm using this piece of code
to create a query like this
There is a few problems with it, I guess because this is a parameterized query and parameters are used as literals (need confirmation on this)?
1. I have to cast
temp.id
to integer in each subquery, otherwise I get PostgresError: operator does not exist: integer = text
. I don't know how that affects performance, but it feels dirty.
2. The query results are of type string
, which I then have to cast again.
3. Also, since the whole query is of type SQL<unknown>
, when parsing the result I need to force the wrong/unwanted type string
onto the typescript compiler first, just to be able to cast the value, like this result.map( v => +(v.id as string) )
Is this really the most optimal way of doing things here, or am I missing something? I found a param
method in drizzle but no docs and no idea how to use it or if it could be useful anyhow. Please enlighten me.1 Reply
To simplify the question. I'm putting in numbers, how can I get numbers out as well?
Forgot to update
The column types in a row constructor are taken from the first row, so all I had to do is add a
CAST()
to the first row, which solved the issues I had