Skip to content
Open
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
3 changes: 2 additions & 1 deletion pypika/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,8 @@ def _apply_pagination(self, querystring: str, **kwargs) -> str:

def _with_sql(self, **kwargs: Any) -> str:
return "WITH " + ",".join(
clause.name + " AS (" + clause.get_sql(subquery=False, with_alias=False, **kwargs) + ") "
format_quotes(clause.name, kwargs.get('alias_quote_char') or kwargs.get('quote_char')) +
" AS (" + clause.get_sql(subquery=False, with_alias=False, **kwargs) + ") "
for clause in self._with
)

Expand Down
2 changes: 1 addition & 1 deletion pypika/tests/test_inserts.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_insert_with_statement(self):

q = Query().with_(sub_query, 'sub_qs').into(self.table_abc).select(aliased.id).from_(aliased)
self.assertEqual(
'WITH sub_qs AS (SELECT "id" FROM "abc") INSERT INTO "abc" SELECT "sub_qs"."id" FROM sub_qs', str(q)
'WITH "sub_qs" AS (SELECT "id" FROM "abc") INSERT INTO "abc" SELECT "sub_qs"."id" FROM sub_qs', str(q)
)


Expand Down
6 changes: 3 additions & 3 deletions pypika/tests/test_selects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ def test_with(self):
test_query = Query.with_(sub_query, "an_alias").from_(AliasedQuery("an_alias")).select("*")

self.assertEqual(
'WITH an_alias AS (SELECT "fizz" FROM "efg") SELECT * FROM an_alias',
'WITH "an_alias" AS (SELECT "fizz" FROM "efg") SELECT * FROM an_alias',
str(test_query),
)

Expand All @@ -1305,7 +1305,7 @@ def test_join_with_with(self):
.select("*")
)
self.assertEqual(
'WITH an_alias AS (SELECT "fizz" FROM "efg") '
'WITH "an_alias" AS (SELECT "fizz" FROM "efg") '
'SELECT * FROM "abc" JOIN an_alias ON "an_alias"."fizz"="abc"."buzz"',
str(test_query),
)
Expand All @@ -1314,7 +1314,7 @@ def test_select_from_with_returning(self):
sub_query = PostgreSQLQuery.into(self.table_abc).insert(1).returning('*')
test_query = Query.with_(sub_query, "an_alias").from_(AliasedQuery("an_alias")).select("*")
self.assertEqual(
'WITH an_alias AS (INSERT INTO "abc" VALUES (1) RETURNING *) SELECT * FROM an_alias', str(test_query)
'WITH "an_alias" AS (INSERT INTO "abc" VALUES (1) RETURNING *) SELECT * FROM an_alias', str(test_query)
)


Expand Down
2 changes: 1 addition & 1 deletion pypika/tests/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_update_with_statement(self):
.where(self.table_abc.comp.eq(an_alias.alias_comp))
)
self.assertEqual(
'WITH an_alias AS (SELECT "fizz" FROM "efg") '
'WITH "an_alias" AS (SELECT "fizz" FROM "efg") '
'UPDATE "abc" SET "lname"="an_alias"."long_name" FROM an_alias '
'WHERE "abc"."comp"="an_alias"."alias_comp"',
str(q),
Expand Down