diff options
| author | Ants Aasma <ants.aasma@gmail.com> | 2007-10-02 23:57:54 +0000 |
|---|---|---|
| committer | Ants Aasma <ants.aasma@gmail.com> | 2007-10-02 23:57:54 +0000 |
| commit | e82ca71cc5c4175f071cdd72207ec04e58a6498c (patch) | |
| tree | 74e56b7bef7b9ea082a0b0c296e414fe8686d254 /test/sql/select.py | |
| parent | 73b0c40946ddcf4f4cbbccb90e81fd914143576d (diff) | |
| download | sqlalchemy-e82ca71cc5c4175f071cdd72207ec04e58a6498c.tar.gz | |
add support for returning results from inserts and updates for postgresql 8.2+. [ticket:797]
Diffstat (limited to 'test/sql/select.py')
| -rw-r--r-- | test/sql/select.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/sql/select.py b/test/sql/select.py index 1114f1735..4cdac97d8 100644 --- a/test/sql/select.py +++ b/test/sql/select.py @@ -1184,7 +1184,35 @@ class CRUDTest(SQLCompileTest): s = select([table2.c.othername], table2.c.otherid == table1.c.myid) u = table1.update(table1.c.name==s) self.assert_compile(u, "UPDATE mytable SET myid=:myid, name=:name, description=:description WHERE mytable.name = (SELECT myothertable.othername FROM myothertable WHERE myothertable.otherid = mytable.myid)") + + @testing.supported('postgres') + def testupdatereturning(self): + dialect = postgres.dialect() + + u = update(table1, values=dict(name='foo'), postgres_returning=[table1.c.myid, table1.c.name]) + self.assert_compile(u, "UPDATE mytable SET name=%(name)s RETURNING mytable.myid, mytable.name", dialect=dialect) + + u = update(table1, values=dict(name='foo'), postgres_returning=[table1]) + self.assert_compile(u, "UPDATE mytable SET name=%(name)s "\ + "RETURNING mytable.myid, mytable.name, mytable.description", dialect=dialect) + + u = update(table1, values=dict(name='foo'), postgres_returning=[func.length(table1.c.name)]) + self.assert_compile(u, "UPDATE mytable SET name=%(name)s RETURNING length(mytable.name)", dialect=dialect) + @testing.supported('postgres') + def testinsertreturning(self): + dialect = postgres.dialect() + + i = insert(table1, values=dict(name='foo'), postgres_returning=[table1.c.myid, table1.c.name]) + self.assert_compile(i, "INSERT INTO mytable (name) VALUES (%(name)s) RETURNING mytable.myid, mytable.name", dialect=dialect) + + i = insert(table1, values=dict(name='foo'), postgres_returning=[table1]) + self.assert_compile(i, "INSERT INTO mytable (name) VALUES (%(name)s) "\ + "RETURNING mytable.myid, mytable.name, mytable.description", dialect=dialect) + + i = insert(table1, values=dict(name='foo'), postgres_returning=[func.length(table1.c.name)]) + self.assert_compile(i, "INSERT INTO mytable (name) VALUES (%(name)s) RETURNING length(mytable.name)", dialect=dialect) + def testdelete(self): self.assert_compile(delete(table1, table1.c.myid == 7), "DELETE FROM mytable WHERE mytable.myid = :mytable_myid") |
