2

using sqlc to generate db methods. Have below query

-- name: RemoveRows:exec
DELETE FROM demotable
WHERE last_updated < (CURRENT_TIMESTAMP - INTERVAL '30' SECOND);

I want to pass 30 as parameter but I used below query, then quotes are not coming and db giving error.

-- name: RemoveRows:exec
DELETE FROM demotable
WHERE last_updated < (CURRENT_TIMESTAMP - INTERVAL $1 SECOND);

Tried quoting $1 but sqlc thinking it is string

-- name: RemoveRows:exec
DELETE FROM demotable
WHERE last_updated < (CURRENT_TIMESTAMP - INTERVAL '$1' SECOND);
PSKP
  • 1,178
  • 14
  • 28

1 Answers1

2

Or rather than mucking around trying to trick the type system just do

... - ($1 * interval '1 minute')
Richard Huxton
  • 21,516
  • 3
  • 39
  • 51