- Notifications
You must be signed in to change notification settings - Fork976
How to custom the interval data type?#2580
-
I have this query: I want the methodCreateSnippet also taking a day number (like 7) as an argument or even the whole interval as an argument. What should I do? |
BetaWas this translation helpful?Give feedback.
All reactions
If you usepgx/v5 as your driver then it looks like sqlc will give you apgtype.Interval to use as a parameter, which is probably pretty comfortable to use.https://play.sqlc.dev/p/0ae27106633b32760f9c1072009605e1b294a1ed7563290509c7daa462796a31
If you're not usingpgx/v5 then I think the above suggestion from@orisano to useMAKE_INTERVAL is best:https://play.sqlc.dev/p/147a2e77fe7e64ffd21af152bb67e447b616bf388410a225df25bde7ed1f0f5e
Replies: 2 comments 2 replies
-
Please use MAKE_INTERVAL or |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
If you use If you're not using |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
hi, I tried the approach with a SELECT query like the following: SELECT*FROM tableWHERE create_date>= NOW()- INTERVAL $1 And is failing with sqlc I'm using the generated code: queries.TestQuery(ctx, pgtype.Interval{Days:7,Valid:true}) Do you know what I'm missing? |
BetaWas this translation helpful?Give feedback.
All reactions
-
I had the same issue as@soasada and solved it by type casting the parameter like: SELECT*FROM tableWHERE create_date>= NOW()- $1::INTERVAL Versions:
|
BetaWas this translation helpful?Give feedback.