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: 3 additions & 0 deletions pypika/dialects.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,9 @@ def get_sql(self, with_alias: bool = False, subquery: bool = False, **kwargs: An

querystring = super(PostgreSQLQueryBuilder, self).get_sql(with_alias, subquery, **kwargs)

if querystring == '':
return ''

querystring += self._on_conflict_sql(**kwargs)
querystring += self._on_conflict_action_sql(**kwargs)

Expand Down
10 changes: 10 additions & 0 deletions pypika/tests/test_inserts.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ def test_on_conflict_where_complex(self):
str(qs),
)

def test_on_conflict_no_inserts(self):
query = PostgreSQLQuery.into(self.table_abc).on_conflict("id").do_nothing()

self.assertEqual('', str(query))


class PostgresInsertIntoReturningTests(unittest.TestCase):
table_abc = Table("abc")
Expand Down Expand Up @@ -567,6 +572,11 @@ def test_insert_returning_from_other_table(self):
with self.assertRaises(QueryException):
PostgreSQLQuery.into(self.table_abc).insert(1).returning(table_cba.id)

def test_insert_returning_no_inserts(self):
query = PostgreSQLQuery.into(self.table_abc).returning(self.table_abc.star)

self.assertEqual('', str(query))


class InsertIntoOnDuplicateTests(unittest.TestCase):
table_abc = Table("abc")
Expand Down
5 changes: 5 additions & 0 deletions pypika/tests/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ def test_update_returning_star(self):

self.assertEqual('UPDATE "abc" SET "foo"=\'bar\' WHERE "foo"=0 RETURNING *', str(q))

def test_update_returning_no_updates(self):
q = PostgreSQLQuery.update(self.table_abc).returning(self.table_abc.star)

self.assertEqual('', str(q))


class SQLLiteUpdateTests(unittest.TestCase):
table_abc = Table("abc")
Expand Down