]> 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 19:29:34 +0000 (20:29 +0100)
Fixed compilation of ``TABLE`` function when used in a from clause
in Oracle Database dialect.

Fixes: #12100
Change-Id: I862e5be9685611dc74338c37b7537505fc2194e5

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 39853087498d6efa6e5f7971ba388260c8618ae2..2ac155cb9ef3d5cadc4f56bf8582c80e9b4af1df 100644 (file)
@@ -863,7 +863,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 972c60d6e7b49ee344bc4c759b5f71766251bc01..b9f11647318fae15672a6dd3e26c4affb8e50a87 100644 (file)
@@ -1903,3 +1903,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)",
+        )