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
1 change: 1 addition & 0 deletions sqlglot/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2386,6 +2386,7 @@ class Insert(DDL, DML):
"partition": False,
"settings": False,
"source": False,
"default": False,
}

def with_(
Expand Down
3 changes: 2 additions & 1 deletion sqlglot/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1952,10 +1952,11 @@ def insert_sql(self, expression: exp.Insert) -> str:
on_conflict = self.sql(expression, "conflict")
on_conflict = f" {on_conflict}" if on_conflict else ""
by_name = " BY NAME" if expression.args.get("by_name") else ""
default_values = "DEFAULT VALUES" if expression.args.get("default") else ""
returning = self.sql(expression, "returning")

if self.RETURNING_END:
expression_sql = f"{expression_sql}{on_conflict}{returning}"
expression_sql = f"{expression_sql}{on_conflict}{default_values}{returning}"
else:
expression_sql = f"{returning}{expression_sql}{on_conflict}"

Expand Down
1 change: 1 addition & 0 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2962,6 +2962,7 @@ def _parse_insert(self) -> t.Union[exp.Insert, exp.MultitableInserts]:
where=self._match_pair(TokenType.REPLACE, TokenType.WHERE) and self._parse_assignment(),
partition=self._match(TokenType.PARTITION_BY) and self._parse_partitioned_by(),
settings=self._match_text_seq("SETTINGS") and self._parse_settings_property(),
default=self._match_text_seq("DEFAULT", "VALUES"),
expression=self._parse_derived_table_values() or self._parse_ddl_select(),
conflict=self._parse_on_conflict(),
returning=returning or self._parse_returning(),
Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ def test_duckdb(self):
self.validate_identity(
"ARG_MAX(keyword_name, keyword_category, 3 ORDER BY keyword_name DESC)"
)
self.validate_identity("INSERT INTO t DEFAULT VALUES RETURNING (c1)")
self.validate_identity("CREATE TABLE notes (watermark TEXT)")
self.validate_identity("SELECT LIST_TRANSFORM([5, NULL, 6], LAMBDA x : COALESCE(x, 0) + 1)")
self.validate_identity("SELECT LIST_TRANSFORM(nbr, LAMBDA x : x + 1) FROM article AS a")
Expand Down