summaryrefslogtreecommitdiff
path: root/test/sql/test_functions.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-04-03 11:28:57 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-04-03 11:30:09 -0400
commitc315c7401a2aa00a8a0fa0f7d4189a9976fd7962 (patch)
tree0a4b5c4195d15d1e7294cc39589060660f1d5930 /test/sql/test_functions.py
parent1dffb7cedeb009ca6c532db558bd0588dd846957 (diff)
downloadsqlalchemy-c315c7401a2aa00a8a0fa0f7d4189a9976fd7962.tar.gz
TableValuedAlias generation fixes
Fixed bug in newly implemented :paramref:`.FunctionElement.table_valued.joins_implicitly` feature where the parameter would not automatically propagate from the original :class:`.TableValuedAlias` object to the secondary object produced when calling upon :meth:`.TableValuedAlias.render_derived` or :meth:`.TableValuedAlias.alias`. Additionally repaired these issues in :class:`.TableValuedAlias`: * repaired a potential memory issue which could occur when repeatedly calling :meth:`.TableValuedAlias.render_derived` against successive copies of the same object (for .alias(), we currently have to still continue chaining from the previous element. not sure if this can be improved but this is standard behavior for .alias() elsewhere) * repaired issue where the individual element types would be lost when calling upon :meth:`.TableValuedAlias.render_derived` or :meth:`.TableValuedAlias.alias`. Fixes: #7890 Change-Id: Ie5120c7ff1e5c1bba5aaf77c782a51c637860208
Diffstat (limited to 'test/sql/test_functions.py')
-rw-r--r--test/sql/test_functions.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py
index e08526419..c055bc150 100644
--- a/test/sql/test_functions.py
+++ b/test/sql/test_functions.py
@@ -26,7 +26,6 @@ from sqlalchemy import Table
from sqlalchemy import testing
from sqlalchemy import Text
from sqlalchemy import true
-from sqlalchemy import types as sqltypes
from sqlalchemy.dialects import mysql
from sqlalchemy.dialects import oracle
from sqlalchemy.dialects import postgresql
@@ -37,6 +36,7 @@ from sqlalchemy.sql import functions
from sqlalchemy.sql import LABEL_STYLE_TABLENAME_PLUS_COL
from sqlalchemy.sql import operators
from sqlalchemy.sql import quoted_name
+from sqlalchemy.sql import sqltypes
from sqlalchemy.sql import table
from sqlalchemy.sql.compiler import BIND_TEMPLATES
from sqlalchemy.sql.functions import FunctionElement
@@ -1425,6 +1425,30 @@ class TableValuedCompileTest(fixtures.TestBase, AssertsCompiledSQL):
"LEFT OUTER JOIN b ON unnested.unnested = b.ref",
)
+ def test_render_derived_maintains_tableval_type(self):
+ fn = func.json_something()
+
+ tv = fn.table_valued(column("x", String))
+
+ eq_(tv.column.type, testing.eq_type_affinity(sqltypes.TableValueType))
+ eq_(tv.column.type._elements[0].type, testing.eq_type_affinity(String))
+
+ tv = tv.render_derived()
+ eq_(tv.column.type, testing.eq_type_affinity(sqltypes.TableValueType))
+ eq_(tv.column.type._elements[0].type, testing.eq_type_affinity(String))
+
+ def test_alias_maintains_tableval_type(self):
+ fn = func.json_something()
+
+ tv = fn.table_valued(column("x", String))
+
+ eq_(tv.column.type, testing.eq_type_affinity(sqltypes.TableValueType))
+ eq_(tv.column.type._elements[0].type, testing.eq_type_affinity(String))
+
+ tv = tv.alias()
+ eq_(tv.column.type, testing.eq_type_affinity(sqltypes.TableValueType))
+ eq_(tv.column.type._elements[0].type, testing.eq_type_affinity(String))
+
def test_star_with_ordinality(self):
"""
SELECT * FROM generate_series(4,1,-1) WITH ORDINALITY;