diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-07-24 14:33:50 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-07-24 14:33:50 -0400 |
commit | 0df977ccad63831375d8a7bc6383385c331d9742 (patch) | |
tree | 18d5f67dd70a7fb8090e230b7f86e2c3eece7c26 /test/sql/test_functions.py | |
parent | 07c01b77f16a08cecdad2c80c1283bed46a7f815 (diff) | |
download | sqlalchemy-0df977ccad63831375d8a7bc6383385c331d9742.tar.gz |
- Added a supported :meth:`.FunctionElement.alias` method to functions,
e.g. the ``func`` construct. Previously, behavior for this method
was undefined. The current behavior mimics that of pre-0.9.4,
which is that the function is turned into a single-column FROM
clause with the given alias name, where the column itself is
anonymously named.
fixes #3137
Diffstat (limited to 'test/sql/test_functions.py')
-rw-r--r-- | test/sql/test_functions.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py index 4d066be8a..d3b718645 100644 --- a/test/sql/test_functions.py +++ b/test/sql/test_functions.py @@ -316,6 +316,57 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): expr = func.extract("year", datetime.date(2010, 12, 5)) self.assert_compile(expr, "EXTRACT(year FROM :param_1)") + def test_select_method_one(self): + expr = func.rows("foo") + self.assert_compile( + expr.select(), + "SELECT rows(:rows_2) AS rows_1" + ) + + def test_alias_method_one(self): + expr = func.rows("foo") + self.assert_compile( + expr.alias(), + "rows(:rows_1)" + ) + + def test_select_method_two(self): + expr = func.rows("foo") + self.assert_compile( + select(['*']).select_from(expr.select()), + "SELECT * FROM (SELECT rows(:rows_2) AS rows_1)" + ) + + def test_select_method_three(self): + expr = func.rows("foo") + self.assert_compile( + select(['foo']).select_from(expr), + "SELECT foo FROM rows(:rows_1)" + ) + + def test_alias_method_two(self): + expr = func.rows("foo") + self.assert_compile( + select(['*']).select_from(expr.alias('bar')), + "SELECT * FROM rows(:rows_1) AS bar" + ) + + def test_alias_method_columns(self): + expr = func.rows("foo").alias('bar') + + # this isn't very useful but is the old behavior + # prior to #2974. + # testing here that the expression exports its column + # list in a way that at least doesn't break. + self.assert_compile( + select([expr]), + "SELECT bar.rows_1 FROM rows(:rows_2) AS bar" + ) + + def test_alias_method_columns_two(self): + expr = func.rows("foo").alias('bar') + assert len(expr.c) + class ExecuteTest(fixtures.TestBase): |