Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue parsing gen_random_uuid() in postgres script. #3774

Closed
EdgyEdgemond opened this issue Jul 16, 2024 · 0 comments · Fixed by #3775
Closed

Issue parsing gen_random_uuid() in postgres script. #3774

EdgyEdgemond opened this issue Jul 16, 2024 · 0 comments · Fixed by #3775
Assignees

Comments

@EdgyEdgemond
Copy link
Contributor

Attempting to parse some sql statements I have run into this issue parsing a create statement, others so far are happy, but parsing gen_random_uuid() I get a ParseError for a missing ). The offending query runs in postgres.

Minimal script to reproduce

import sqlglot

stmt = """
CREATE TABLE public.user (
    id                 BIGSERIAL PRIMARY KEY NOT NULL,
    user_id            uuid UNIQUE DEFAULT gen_random_uuid()
);
"""

sqlglot.parse_one(apply, read="postgres", dialect="postgres") 

Stacktrace

Traceback (most recent call last):
  File "/x.py", line 10, in <module>
    sqlglot.parse_one(stmt, read="postgres", dialect="postgres") 
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.12/site-packages/sqlglot/__init__.py", line 136, in parse_one
    result = dialect.parse(sql, **opts)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.12/site-packages/sqlglot/dialects/dialect.py", line 690, in parse
    return self.parser(**opts).parse(self.tokenize(sql), sql)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.12/site-packages/sqlglot/parser.py", line 1287, in parse
    return self._parse(
           ^^^^^^^^^^^^
  File "/.venv/lib/python3.12/site-packages/sqlglot/parser.py", line 1356, in _parse
    expressions.append(parse_method(self))
                       ^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.12/site-packages/sqlglot/parser.py", line 1585, in _parse_statement
    return self.STATEMENT_PARSERS[self._prev.token_type](self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.12/site-packages/sqlglot/parser.py", line 696, in <lambda>
    TokenType.CREATE: lambda self: self._parse_create(),
                                   ^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.12/site-packages/sqlglot/parser.py", line 1727, in _parse_create
    this = self._parse_schema(this=table_parts)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.12/site-packages/sqlglot/parser.py", line 4949, in _parse_schema
    self._match_r_paren()
  File "/.venv/lib/python3.12/site-packages/sqlglot/parser.py", line 6665, in _match_r_paren
    self.raise_error("Expecting )")
  File "/.venv/lib/python3.12/site-packages/sqlglot/parser.py", line 1400, in raise_error
    raise error
sqlglot.errors.ParseError: Expecting ). Line 4, Col: 55.
  (
    id                 BIGSERIAL PRIMARY KEY NOT NULL,
    user_id            uuid UNIQUE DEFAULT gen_random_uuid()
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants