gosqlc

quoted parameters to golang sqlc


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);

Solution

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

    ... - ($1 * interval '1 minute')