diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-09-12 12:57:40 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-09-12 12:58:55 -0400 |
commit | a14e5c42ca78435e5fe6ada35796d6fcf14be32e (patch) | |
tree | af87906115b1d4a6b2fdc23513a6c8bb5597afdf /test/dialect/postgresql/test_compiler.py | |
parent | 21ca9b50c794c58df476300206aefff46511909d (diff) | |
download | sqlalchemy-ticket_4074_11.tar.gz |
use the stack to get the insert statement in on conflictticket_4074_11
Fixed bug in Postgresql :meth:`.postgresql.dml.Insert.on_conflict_do_update`
which would prevent the insert statement from being used as a CTE,
e.g. via :meth:`.Insert.cte`, within another statement.
Change-Id: Ie20972a05e194290bc9d92819750845872949ecc
Fixes: #4074
(cherry picked from commit 70516536107a44230762206342c51239c5d85417)
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r-- | test/dialect/postgresql/test_compiler.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index 0533016cd..18940ed5f 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -1396,6 +1396,30 @@ class InsertOnConflictTest(fixtures.TestBase, AssertsCompiledSQL): "param_1": "somename", "param_2": "unknown"}) + def test_on_conflict_as_cte(self): + i = insert( + self.table1, values=dict(name='foo')) + i = i.on_conflict_do_update( + constraint=self.excl_constr_anon, + set_=dict(name=i.excluded.name), + where=( + (self.table1.c.name != i.excluded.name)) + ).returning(literal_column("1")).cte("i_upsert") + + stmt = select([i]) + + self.assert_compile( + stmt, + "WITH i_upsert AS " + "(INSERT INTO mytable (name) VALUES (%(name)s) " + "ON CONFLICT (name, description) " + "WHERE description != %(description_1)s " + "DO UPDATE SET name = excluded.name " + "WHERE mytable.name != excluded.name RETURNING 1) " + "SELECT i_upsert.1 " + "FROM i_upsert" + ) + def test_quote_raw_string_col(self): t = table('t', column("FancyName"), column("other name")) |