Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions sqlglot/dialects/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ def _build_make_timestamp(args: t.List) -> exp.Expression:
)


def _show_parser(*args: t.Any, **kwargs: t.Any) -> t.Callable[[DuckDB.Parser], exp.Show]:
def _parse(self: DuckDB.Parser) -> exp.Show:
return self._parse_show_duckdb(*args, **kwargs)

return _parse


def _struct_sql(self: DuckDB.Generator, expression: exp.Struct) -> str:
args: t.List[str] = []

Expand Down Expand Up @@ -348,6 +355,8 @@ class Tokenizer(tokens.Tokenizer):
"$": TokenType.PARAMETER,
}

COMMANDS = tokens.Tokenizer.COMMANDS - {TokenType.SHOW}

class Parser(parser.Parser):
BITWISE = {
**parser.Parser.BITWISE,
Expand All @@ -369,6 +378,11 @@ class Parser(parser.Parser):

FUNCTIONS_WITH_ALIASED_ARGS = {*parser.Parser.FUNCTIONS_WITH_ALIASED_ARGS, "STRUCT_PACK"}

SHOW_PARSERS = {
"TABLES": _show_parser("TABLES"),
"ALL TABLES": _show_parser("ALL TABLES"),
}

FUNCTIONS = {
**parser.Parser.FUNCTIONS,
"ARRAY_REVERSE_SORT": _build_sort_array_desc,
Expand Down Expand Up @@ -467,6 +481,7 @@ class Parser(parser.Parser):
**parser.Parser.STATEMENT_PARSERS,
TokenType.ATTACH: lambda self: self._parse_attach_detach(),
TokenType.DETACH: lambda self: self._parse_attach_detach(is_attach=False),
TokenType.SHOW: lambda self: self._parse_show(),
}

def _parse_expression(self) -> t.Optional[exp.Expression]:
Expand Down Expand Up @@ -581,6 +596,9 @@ def _parse_attach_option() -> exp.AttachOption:
else self.expression(exp.Detach, this=this, exists=exists)
)

def _parse_show_duckdb(self, this: str) -> exp.Show:
return self.expression(exp.Show, this=this)

class Generator(generator.Generator):
PARAMETER_TOKEN = "$"
NAMED_PLACEHOLDER_TOKEN = "$"
Expand Down
4 changes: 4 additions & 0 deletions tests/dialects/test_duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1598,3 +1598,7 @@ def test_at_sign_to_abs(self):
"SELECT (@-1) + 1",
"SELECT (ABS(-1)) + 1",
)

def test_show_tables(self):
self.validate_identity("SHOW TABLES").assert_is(exp.Show)
self.validate_identity("SHOW ALL TABLES").assert_is(exp.Show)
Loading