summaryrefslogtreecommitdiff
path: root/test/dialect/postgresql/test_compiler.py
diff options
context:
space:
mode:
authorRobin Thomas <robin.thomas@livestream.com>2016-04-13 17:04:40 -0400
committerRobin Thomas <robin.thomas@livestream.com>2016-04-13 17:04:40 -0400
commitb432ff8c4f230c4521ee26b5acdfdc72838845d8 (patch)
treedffc2e77f22ab32057c0080e9432b5d5e5dff309 /test/dialect/postgresql/test_compiler.py
parentcf6ed33ba9185bccbe7f21810422cf3faef5a649 (diff)
downloadsqlalchemy-b432ff8c4f230c4521ee26b5acdfdc72838845d8.tar.gz
working, test-included implementation of PostgreSQL 9.5's
INSERT ... ON CONFLICT ... for common use cases.
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r--test/dialect/postgresql/test_compiler.py23
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',