Replies: 2 comments 6 replies
-
My understanding is that if you know you have a The whole point of template tags thing is to protect queries from SQL injection. You would only have to be concerned if the "number" was coming from user input (such as a form field) in which case you'd want to parse it with zod/valibot/etc or manually using In your case you have the index value returned by a built-in const myNum = 1 // type `number`
const slonikQuery = sql`SELECT ${myNum}` // this is fine In case it helps I have a helper function If you had one of these of your own you could simply use it in all cases like this with confidence. For strings it returns an sql fragment with the value interpolated inside (since at one point the docs suggested against using For |
Beta Was this translation helpful? Give feedback.
-
I am closing this discussion, because I am obviously the only one bothered by the issue I described above. I've made up my mind and I think that using |
Beta Was this translation helpful? Give feedback.
-
In my project, I generate a
group by
clause of a query dynamically from a specified field list.In PostgreSQL, it is possible to refer to an output column in a group by clause by its ordinal number, such as in the following example:
Currently, I am using slonik's
raw
tag to place a literal number into a query based on which fields need to be put into a group by clause, such as in the following snippet:Is it possible to do it without the use of
raw
tag?I thought, that
literalValue
may help, but it accepts only strings. Is there a reason not to allow other primitive values to be used with that function? Thank you.Beta Was this translation helpful? Give feedback.
All reactions