Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions sqlglot/dialects/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ class Tokenizer(tokens.Tokenizer):
"BIGSERIAL": TokenType.BIGSERIAL,
"CONSTRAINT TRIGGER": TokenType.COMMAND,
"CSTRING": TokenType.PSEUDO_TYPE,
"CURRENT_CATALOG": TokenType.CURRENT_CATALOG,
"DECLARE": TokenType.COMMAND,
"DO": TokenType.COMMAND,
"EXEC": TokenType.COMMAND,
Expand Down Expand Up @@ -452,6 +453,7 @@ class Parser(parser.Parser):
NO_PAREN_FUNCTIONS = {
**parser.Parser.NO_PAREN_FUNCTIONS,
TokenType.CURRENT_SCHEMA: exp.CurrentSchema,
TokenType.CURRENT_CATALOG: exp.CurrentCatalog,
}

FUNCTION_PARSERS = {
Expand Down Expand Up @@ -899,3 +901,7 @@ def arraycontains_sql(self, expression: exp.ArrayContains) -> str:
)

return self.sql(case_expr)

def currentcatalog_sql(self, expression: exp.CurrentCatalog) -> str:
this = expression.this
return self.func("CURRENT_CATALOG", this) if this else "CURRENT_CATALOG"
10 changes: 10 additions & 0 deletions sqlglot/dialects/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Tokenizer(Presto.Tokenizer):
KEYWORDS = {
**Presto.Tokenizer.KEYWORDS,
"REFRESH": TokenType.REFRESH,
"CURRENT_CATALOG": TokenType.CURRENT_CATALOG,
}

class Parser(Presto.Parser):
Expand All @@ -31,6 +32,11 @@ class Parser(Presto.Parser):
"LISTAGG": lambda self: self._parse_string_agg(),
}

NO_PAREN_FUNCTIONS = {
**parser.Parser.NO_PAREN_FUNCTIONS,
TokenType.CURRENT_CATALOG: exp.CurrentCatalog,
}

JSON_QUERY_OPTIONS: parser.OPTIONS_TYPE = {
**dict.fromkeys(
("WITH", "WITHOUT"),
Expand Down Expand Up @@ -120,3 +126,7 @@ def jsonextract_sql(self, expression: exp.JSONExtract) -> str:
expression.this,
json_path + option + quote + on_condition,
)

def currentcatalog_sql(self, expression: exp.CurrentCatalog) -> str:
this = expression.this
return self.func("CURRENT_CATALOG", this) if this else "CURRENT_CATALOG"
4 changes: 4 additions & 0 deletions sqlglot/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6356,6 +6356,10 @@ class CurrentUser(Func):
arg_types = {"this": False}


class CurrentCatalog(Func):
arg_types = {"this": False}


class CurrentRegion(Func):
arg_types = {}

Expand Down
1 change: 1 addition & 0 deletions sqlglot/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class TokenType(AutoName):
CURRENT_TIME = auto()
CURRENT_TIMESTAMP = auto()
CURRENT_USER = auto()
CURRENT_CATALOG = auto()
DECLARE = auto()
DEFAULT = auto()
DELETE = auto()
Expand Down
3 changes: 3 additions & 0 deletions tests/dialects/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -1679,3 +1679,6 @@ def test_interval_span(self):
day_time_str = "a > INTERVAL '1 00:00' AND TRUE"
self.validate_identity(day_time_str, "a > INTERVAL '1 00:00' AND TRUE")
self.assertIsInstance(self.parse_one(day_time_str), exp.And)

def test_current_catalog(self):
self.validate_identity("SELECT CURRENT_CATALOG")
3 changes: 3 additions & 0 deletions tests/dialects/test_trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,6 @@ def test_json_value(self):
self.validate_identity(
f"""SELECT JSON_VALUE({json_doc}, 'lax $.price' RETURNING DECIMAL(4, 2) {on_option} ON EMPTY {on_option} ON ERROR) AS price"""
)

def test_current_catalog(self):
self.validate_identity("SELECT CURRENT_CATALOG")