Skip to content

Redshift dialect: -- and /* inside an operator should start a comment #2961

Open

Description

@preston-footprint

Postgres-family lexers never let -- or /* be part of an operator; the operator ends there and a comment starts. sqlparser lexes #- (and |/, ||/) as one token first, which leaves the rest of the comment marker behind.

select 2 #--'
 3, pg_backend_pid() --'
  • sqlparser 0.64.0: HashMinus, Minus, then the string '\n 3, pg_backend_pid() --'; parses as SELECT 2 #- -'...'.
  • Redshift: two columns, 1 (that is, 2 # 3) and 1073905994.

The same happens with /*: select 9 |/*'*/ 2, pg_backend_pid() --' returns 11 and the pid on Redshift, while sqlparser lexes PGSquareRoot, Mul, a string, and fails to parse.

Postgres documents the rule under "Operators" (https://www.postgresql.org/docs/8.0/sql-syntax.html#SQL-SYNTAX-OPERATORS): "-- and /* cannot appear anywhere in an operator name, since they will be taken as the start of a comment." Postgres's own dialect in sqlparser likely has the same gap.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions