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

CREATE TABLE - problem parsing the Teradata WITH DATA clause #1923

Closed
MarkBell920 opened this issue Jul 15, 2023 · 1 comment · Fixed by #1924
Closed

CREATE TABLE - problem parsing the Teradata WITH DATA clause #1923

MarkBell920 opened this issue Jul 15, 2023 · 1 comment · Fixed by #1924

Comments

@MarkBell920
Copy link

There is a problem parsing a CREATE TABLE statement in Teradata that has a WITH DATA clause

sqlglot version 17.2.0
Teradata version 16.20

The SQL is
CREATE VOLATILE SET TABLE example1 AS (
SELECT col1,col2, col3
from table1
)
WITH DATA
PRIMARY INDEX (col1)
ON COMMIT PRESERVE ROWS;

and code is
for statement in sqlglot.parse(sql, read="teradata"):
for table in statement.find_all(exp.Table):
print(table.name)

commenting out the with clause will work. Error message is


ParseError Traceback (most recent call last)
Cell In[21], line 1
----> 1 for statement in sqlglot.parse(raw_sql, read="teradata"):
2 for table in statement.find_all(exp.Table):
3 print(table.name)

File ~\AppData\Roaming\Python\Python311\site-packages\sqlglot_init_.py:83, in parse(sql, read, **opts)
71 """
72 Parses the given SQL string into a collection of syntax trees, one per parsed SQL statement.
73
(...)
80 The resulting syntax tree collection.
81 """
82 dialect = Dialect.get_or_raise(read)()
---> 83 return dialect.parse(sql, **opts)

File ~\AppData\Roaming\Python\Python311\site-packages\sqlglot\dialects\dialect.py:278, in Dialect.parse(self, sql, **opts)
277 def parse(self, sql: str, **opts) -> t.List[t.Optional[exp.Expression]]:
--> 278 return self.parser(**opts).parse(self.tokenize(sql), sql)

File ~\AppData\Roaming\Python\Python311\site-packages\sqlglot\parser.py:877, in Parser.parse(self, raw_tokens, sql)
863 def parse(
864 self, raw_tokens: t.List[Token], sql: t.Optional[str] = None
865 ) -> t.List[t.Optional[exp.Expression]]:
866 """
867 Parses a list of tokens and returns a list of syntax trees, one tree
868 per parsed SQL statement.
(...)
875 The list of the produced syntax trees.
876 """
--> 877 return self._parse(
878 parse_method=self.class._parse_statement, raw_tokens=raw_tokens, sql=sql
879 )

File ~\AppData\Roaming\Python\Python311\site-packages\sqlglot\parser.py:946, in Parser._parse(self, parse_method, raw_tokens, sql)
943 expressions.append(parse_method(self))
945 if self._index < len(self._tokens):
--> 946 self.raise_error("Invalid expression / Unexpected token")
948 self.check_errors()
950 return expressions

File ~\AppData\Roaming\Python\Python311\site-packages\sqlglot\parser.py:987, in Parser.raise_error(self, message, token)
975 error = ParseError.new(
976 f"{message}. Line {token.line}, Col: {token.col}.\n"
977 f" {start_context}\033[4m{highlight}\033[0m{end_context}",
(...)
983 end_context=end_context,
984 )
986 if self.error_level == ErrorLevel.IMMEDIATE:
--> 987 raise error
989 self.errors.append(error)

ParseError: Invalid expression / Unexpected token. Line 7, Col: 7.

CREATE VOLATILE SET TABLE example1 AS (
SELECT col1,col2, col3
from table1
)
WITH DATA
PRIMARY INDEX (col1)
ON COMMIT PRESERVE ROWS;

@MarkBell920 MarkBell920 changed the title CREATE TABLE - problem parsing the with Teradata WITH DATA clause CREATE TABLE - problem parsing the Teradata WITH DATA clause Jul 15, 2023
@tobymao
Copy link
Owner

tobymao commented Jul 15, 2023

will look into this later today, or feel free to submit a pr, it should be easy

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