From: Federico Caselli Date: Thu, 14 Nov 2024 19:27:35 +0000 (+0100) Subject: Support table function in oracle X-Git-Tag: rel_2_0_37~36^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5e9a64f037cffba9ddd6046f097b80c6ee5ff907;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Support table function in oracle Fixed compilation of ``TABLE`` function when used in a from clause in Oracle Database dialect. Fixes: #12100 Change-Id: I862e5be9685611dc74338c37b7537505fc2194e5 (cherry picked from commit 564de4661fce3274d71c32676a735a250821fc0f) --- diff --git a/doc/build/changelog/unreleased_20/12100.rst b/doc/build/changelog/unreleased_20/12100.rst new file mode 100644 index 0000000000..5fc111ae49 --- /dev/null +++ b/doc/build/changelog/unreleased_20/12100.rst @@ -0,0 +1,6 @@ +.. change:: + :tags: bug, oracle + :tickets: 12100 + + Fixed compilation of ``TABLE`` function when used in a from clause + in Oracle Database dialect. diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index b03fbc9d06..14a88d1c62 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -851,7 +851,7 @@ class OracleCompiler(compiler.SQLCompiler): def visit_function(self, func, **kw): text = super().visit_function(func, **kw) - if kw.get("asfrom", False): + if kw.get("asfrom", False) and func.name.lower() != "table": text = "TABLE (%s)" % text return text diff --git a/test/dialect/oracle/test_compiler.py b/test/dialect/oracle/test_compiler.py index 560298800e..532d08c662 100644 --- a/test/dialect/oracle/test_compiler.py +++ b/test/dialect/oracle/test_compiler.py @@ -1852,3 +1852,15 @@ class TableValuedFunctionTest(fixtures.TestBase, testing.AssertsCompiledSQL): "SELECT anon_1.string1, anon_1.string2 " "FROM TABLE (three_pairs()) anon_1", ) + + @testing.combinations(func.TABLE, func.table, func.Table) + def test_table_function(self, fn): + """Issue #12100 Use case is: + https://python-oracledb.readthedocs.io/en/latest/user_guide/bind.html#binding-a-large-number-of-items-in-an-in-list + """ + fn_call = fn("simulate_name_array") + stmt = select(1).select_from(fn_call) + self.assert_compile( + stmt, + f"SELECT 1 FROM {fn_call.name}(:{fn_call.name}_1)", + )