]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Postgres: Do not prefix table with schema in: "FOR UPDATE of <table>"
authorDiana Clarke <diana.joan.clarke@gmail.com>
Tue, 24 Nov 2015 18:41:07 +0000 (13:41 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 30 Nov 2015 18:06:39 +0000 (13:06 -0500)
For example, this query:

    SELECT s1.users.name FROM s1.users FOR UPDATE OF s1.users

should actually be:

    SELECT s1.users.name FROM s1.users FOR UPDATE OF users

fixes #3573

(cherry picked from commit fd47fea6fbb11ee84b7eea5772f40855703ebe47)

lib/sqlalchemy/dialects/postgresql/base.py
lib/sqlalchemy/sql/compiler.py
test/dialect/postgresql/test_compiler.py

index 5a0dbd4758ebd3b4c9e53584ecaf261e5835f4a0..363f5c58eeffe91841fb562cde2ee0dba346f4b7 100644 (file)
@@ -1546,7 +1546,7 @@ class PGCompiler(compiler.SQLCompiler):
                 c.table if isinstance(c, expression.ColumnClause)
                 else c for c in select._for_update_arg.of)
             tmp += " OF " + ", ".join(
-                self.process(table, ashint=True, **kw)
+                self.process(table, ashint=True, use_schema=False, **kw)
                 for table in tables
             )
 
index a036dcc4238db4693a812cd599fe7670bd50dcb9..da45a93f390b1adf5b15f01328b965a08c4db3d7 100644 (file)
@@ -1786,9 +1786,9 @@ class SQLCompiler(Compiled):
         return text
 
     def visit_table(self, table, asfrom=False, iscrud=False, ashint=False,
-                    fromhints=None, **kwargs):
+                    fromhints=None, use_schema=True, **kwargs):
         if asfrom or ashint:
-            if getattr(table, "schema", None):
+            if use_schema and getattr(table, "schema", None):
                 ret = self.preparer.quote_schema(table.schema) + \
                     "." + self.preparer.quote(table.name)
             else:
index 427ffc2adf9cfd88992f9053b78d4c995eae352e..e01b9ab9846908e3668fd2dd92597876bc9ad612 100644 (file)
@@ -591,6 +591,22 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
             "WHERE mytable_1.myid = %(myid_1)s FOR UPDATE OF mytable_1"
         )
 
+    def test_for_update_with_schema(self):
+        m = MetaData()
+        table1 = Table(
+            'mytable', m,
+            Column('myid'),
+            Column('name'),
+            schema='testschema'
+        )
+
+        self.assert_compile(
+            table1.select(table1.c.myid == 7).with_for_update(of=table1),
+            "SELECT testschema.mytable.myid, testschema.mytable.name "
+            "FROM testschema.mytable "
+            "WHERE testschema.mytable.myid = %(myid_1)s "
+            "FOR UPDATE OF mytable")
+
     def test_reserved_words(self):
         table = Table("pg_table", MetaData(),
                       Column("col1", Integer),