diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-06-21 16:32:38 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-06-21 16:32:38 -0400 |
commit | d5609d77841ab4e607e6b372a15396b38ddace9a (patch) | |
tree | eb6faaeed9e58ed6d87b675eb0c27f363fc4de56 /test/dialect/test_postgresql.py | |
parent | 2272f30af435c5283157724bbb16fb0a573159ce (diff) | |
download | sqlalchemy-d5609d77841ab4e607e6b372a15396b38ddace9a.tar.gz |
- [feature] Added "MATCH" clause to ForeignKey,
ForeignKeyConstraint, courtesy Ryan Kelly.
[ticket:2502]
- [feature] Added support for DELETE and UPDATE from
an alias of a table, which would assumedly
be related to itself elsewhere in the query,
courtesy Ryan Kelly. [ticket:2507]
- [feature] Added support for the Postgresql ONLY
keyword, which can appear corresponding to a
table in a SELECT, UPDATE, or DELETE statement.
The phrase is established using with_hint().
Courtesy Ryan Kelly [ticket:2506]
Diffstat (limited to 'test/dialect/test_postgresql.py')
-rw-r--r-- | test/dialect/test_postgresql.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index 5729bf354..b50b0dcbb 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -272,6 +272,56 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile(x, '''SELECT pg_table.col1, pg_table."variadic" FROM pg_table''') + def test_from_only(self): + m = MetaData() + tbl1 = Table('testtbl1', m, Column('id', Integer)) + tbl2 = Table('testtbl2', m, Column('id', Integer)) + + stmt = tbl1.select().with_hint(tbl1, 'ONLY', 'postgresql') + expected = 'SELECT testtbl1.id FROM ONLY testtbl1' + self.assert_compile(stmt, expected) + + talias1 = tbl1.alias('foo') + stmt = talias1.select().with_hint(talias1, 'ONLY', 'postgresql') + expected = 'SELECT foo.id FROM ONLY testtbl1 AS foo' + self.assert_compile(stmt, expected) + + stmt = select([tbl1, tbl2]).with_hint(tbl1, 'ONLY', 'postgresql') + expected = ('SELECT testtbl1.id, testtbl2.id FROM ONLY testtbl1, ' + 'testtbl2') + self.assert_compile(stmt, expected) + + stmt = select([tbl1, tbl2]).with_hint(tbl2, 'ONLY', 'postgresql') + expected = ('SELECT testtbl1.id, testtbl2.id FROM testtbl1, ONLY ' + 'testtbl2') + self.assert_compile(stmt, expected) + + stmt = select([tbl1, tbl2]) + stmt = stmt.with_hint(tbl1, 'ONLY', 'postgresql') + stmt = stmt.with_hint(tbl2, 'ONLY', 'postgresql') + expected = ('SELECT testtbl1.id, testtbl2.id FROM ONLY testtbl1, ' + 'ONLY testtbl2') + self.assert_compile(stmt, expected) + + stmt = update(tbl1, values=dict(id=1)) + stmt = stmt.with_hint('ONLY', dialect_name='postgresql') + expected = 'UPDATE ONLY testtbl1 SET id=%(id)s' + self.assert_compile(stmt, expected) + + stmt = delete(tbl1).with_hint('ONLY', selectable=tbl1, dialect_name='postgresql') + expected = 'DELETE FROM ONLY testtbl1' + self.assert_compile(stmt, expected) + + tbl3 = Table('testtbl3', m, Column('id', Integer), schema='testschema') + stmt = tbl3.select().with_hint(tbl3, 'ONLY', 'postgresql') + expected = 'SELECT testschema.testtbl3.id FROM ONLY testschema.testtbl3' + self.assert_compile(stmt, expected) + + assert_raises( + exc.CompileError, + tbl3.select().with_hint(tbl3, "FAKE", "postgresql").compile, + dialect=postgresql.dialect() + ) class FloatCoercionTest(fixtures.TablesTest, AssertsExecutionResults): __only_on__ = 'postgresql' |