diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-08-27 10:28:01 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-08-27 10:32:21 -0400 |
commit | 5295a683f9acdad59871ad7b7e6cead834c899e2 (patch) | |
tree | fc7c153957e5ab81360e49e53bda00353891a142 /test/dialect/postgresql/test_compiler.py | |
parent | 4d63b472f272138eca0286fd6c4a7bf52e9be3c3 (diff) | |
download | sqlalchemy-5295a683f9acdad59871ad7b7e6cead834c899e2.tar.gz |
- add PG-specific aggregate_order_by(), references #3132
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r-- | test/dialect/postgresql/test_compiler.py | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index 0407dcb81..78217bd82 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -12,8 +12,10 @@ from sqlalchemy import exc, schema from sqlalchemy.dialects import postgresql from sqlalchemy.dialects.postgresql import TSRANGE from sqlalchemy.orm import mapper, aliased, Session -from sqlalchemy.sql import table, column, operators +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 class SequenceTest(fixtures.TestBase, AssertsCompiledSQL): @@ -800,6 +802,48 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): dialect=postgresql.dialect() ) + def test_aggregate_order_by_one(self): + m = MetaData() + table = Table('table1', m, Column('a', Integer), Column('b', Integer)) + expr = func.array_agg(aggregate_order_by(table.c.a, table.c.b.desc())) + stmt = select([expr]) + + # note this tests that the object exports FROM objects + # correctly + self.assert_compile( + stmt, + "SELECT array_agg(table1.a ORDER BY table1.b DESC) " + "AS array_agg_1 FROM table1" + ) + + def test_aggregate_order_by_two(self): + m = MetaData() + table = Table('table1', m, Column('a', Integer), Column('b', Integer)) + expr = func.string_agg( + table.c.a, + aggregate_order_by(literal_column("','"), table.c.a) + ) + stmt = select([expr]) + + self.assert_compile( + stmt, + "SELECT string_agg(table1.a, ',' ORDER BY table1.a) " + "AS string_agg_1 FROM table1" + ) + + def test_aggregate_order_by_adapt(self): + m = MetaData() + table = Table('table1', m, Column('a', Integer), Column('b', Integer)) + expr = func.array_agg(aggregate_order_by(table.c.a, table.c.b.desc())) + stmt = select([expr]) + + a1 = table.alias('foo') + stmt2 = sql_util.ClauseAdapter(a1).traverse(stmt) + self.assert_compile( + stmt2, + "SELECT array_agg(foo.a ORDER BY foo.b DESC) AS array_agg_1 FROM table1 AS foo" + ) + class DistinctOnTest(fixtures.TestBase, AssertsCompiledSQL): |