diff options
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
| -rw-r--r-- | test/dialect/postgresql/test_compiler.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index 87e48d3f2..ae8907180 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -16,6 +16,7 @@ from sqlalchemy.sql import table, column, operators, literal_column from sqlalchemy.sql import util as sql_util from sqlalchemy.util import u from sqlalchemy.dialects.postgresql import aggregate_order_by +from sqlalchemy.dialects.postgresql.on_conflict import DoNothing, DoUpdate class SequenceTest(fixtures.TestBase, AssertsCompiledSQL): @@ -90,6 +91,28 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): 'RETURNING length(mytable.name) AS length_1', dialect=dialect) + def test_insert_on_conflict(self): + dialect = postgresql.dialect() + table1 = table('mytable', + column('myid', Integer), + column('name', String(128)), + column('description', String(128)), + ) + + i = insert( + table1, + values=dict( + name='foo'), postgresql_on_conflict=DoNothing()) + self.assert_compile(i, + 'INSERT INTO mytable (name) VALUES ' + '(%(name)s) ON CONFLICT DO NOTHING', + dialect=dialect) + i = insert(table1, values=dict(name='foo'), postgresql_on_conflict=DoUpdate(table1.c.myid).with_excluded('foo')) + self.assert_compile(i, + 'INSERT INTO mytable (name) VALUES ' + '(%(name)s) ON CONFLICT (myid) DO UPDATE SET foo = excluded.foo', + dialect=dialect) + def test_insert_returning(self): dialect = postgresql.dialect() table1 = table('mytable', |
