You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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\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 )
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;
The text was updated successfully, but these errors were encountered:
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
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;
The text was updated successfully, but these errors were encountered: