Skip to content

Can't use name parameters for less than/greater than conditions #1439

Closed

Description

@danthegoodman1

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

Activity

  1. added
    bugSomething isn't working
    triageNew issues that hasn't been reviewed
    on Feb 15, 2022
  2. danielbprice commented on Mar 31, 2022

    @danielbprice
    Contributor

    @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.

  3. danthegoodman1 commented on Apr 2, 2022

    @danthegoodman1
    Author

    Ahh that could make sense, will have to try

  4. bokunodev commented on Jul 13, 2022

    @bokunodev

    using the verbose sqlc.arg or narg work though.

  5. kyleconroy commented on Aug 28, 2022

    @kyleconroy
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions