sqlc
sqlc copied to clipboard
Can't use name parameters for less than/greater than conditions
Version
1.12.0
What happened?
I tried to use named params for greater than check, but I get a syntax error. Works with $1 in place of @offset. Also sqlc.arg does not work either.
Relevant log output
# package query
queries/relations.sql:1:1: syntax error at or near "offset"
Database schema
CREATE TABLE IF NOT EXISTS permission_group_membership (
group_name TEXT NOT NULL,
entity TEXT NOT NULL,
ns TEXT NOT NULL,
object TEXT NOT NULL,
PRIMARY KEY(ns, group_name, entity)
);
SQL queries
SELECT *
FROM permission_group_membership
WHERE entity > @offset
LIMIT 50;
Configuration
version: 1
packages:
- path: "query"
name: "query"
engine: "postgresql"
schema: "sqlcSchema.sql"
queries: "./queries/"
sql_package: "pgx/v4"
Playground URL
No response
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
@danthegoodman1 I think that what you are hitting here is a problem with the use of the token offset-- which is also reserved in SQL (i.e. LIMIT and OFFSET). I plugged your code into the sqlc playground and reproduced the problem, but when I changed offset to theoffset it worked. Dunno if that helps.
https://play.sqlc.dev/p/6073003aaa3db6eae4250aee0de4c82ed28c7864064671fd50761341a9a900d0
Possibly it would be good to update the title of the issue to "cannot use offset as an input param name" or similar. You might need to experiment to see how widespread this problem is, I don't know. I tried limit and it produced a similar issue.
Ahh that could make sense, will have to try
using the verbose sqlc.arg or narg work though.
Closing this one as there are two workarounds. I'm not sure we'll be able to get around using a reserved word with short-hand syntax.