]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Support table function in oracle
authorFederico Caselli <cfederico87@gmail.com>
Thu, 14 Nov 2024 19:27:35 +0000 (20:27 +0100)
committerFederico Caselli <cfederico87@gmail.com>
Thu, 14 Nov 2024 23:14:30 +0000 (00:14 +0100)
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)

doc/build/changelog/unreleased_20/12100.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/oracle/base.py
test/dialect/oracle/test_compiler.py

diff --git a/doc/build/changelog/unreleased_20/12100.rst b/doc/build/changelog/unreleased_20/12100.rst
new file mode 100644 (file)
index 0000000..5fc111a
--- /dev/null
@@ -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.
index b03fbc9d06b1c413aa5aafe6a29a1e480380ade1..14a88d1c629e501f83577ed184757d55d212b137 100644 (file)
@@ -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
 
index 560298800e7c579c6ad62123f5372e87eafa70ba..532d08c6626ce02c3a7d8bbe0c93f0d1a5d5ca34 100644 (file)
@@ -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)",
+        )