]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
SQL codestyle: trim spacing around 'INHERITS' table list
authorJames Addison <james@reciperadar.com>
Sat, 4 Jul 2026 08:02:35 +0000 (04:02 -0400)
committersqla-tester <sqla-tester@sqlalchemy.org>
Sat, 4 Jul 2026 08:02:35 +0000 (04:02 -0400)
### Description
This is _pedantic_ consistency with other comma-separated SQL lists - e.g. `VALUES`, `IN`, `DISTINCT ON` - and subqueries, where generally parantheses are not inner-padded by space characters.

The test cases updated illustrate the difference:

```diff
-            "CREATE TABLE atable (id INTEGER) INHERITS ( i1 )",
+            "CREATE TABLE atable (id INTEGER) INHERITS (i1)",
```

```diff
-            "CREATE TABLE atable (id INTEGER) INHERITS ( i1, i2 )",
+            "CREATE TABLE atable (id INTEGER) INHERITS (i1, i2)",

```

I noticed during source code diff review between [v2.0.50 and v2.0.51](https://github.com/sqlalchemy/sqlalchemy/compare/rel_2_0_50...rel_2_0_51) that spaces are added on each side within the parentheses containing the inherited table list.

If it's intentional to draw attention to the fact that these are tables and not column names -- then my apologies, that would seem sorta reasonable.

The parsing/interpretation of these spaces seems unlikely to be the change that microscopically moves the performance needle enough to offset the climate crisis -- indeed the overhead of reading this and responding may be larger -- this is purely me being pedantic.

### Checklist

This pull request is:

- [x] A documentation / typographical / small typing error fix
- Good to go, no issue or tests are needed

**Have a nice day!**
(you too; plus weekend)

Closes: #13397
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/13397
Pull-request-sha: 1324c758b81eb80fff70e706a8171d24b885d1a2

Change-Id: I23640361f6539daaee1260840b9fbe6d0a4ca05a

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

index cbee52ba215397f06644030b6b0b205fa7c7a204..5a815bfa7ba646fc2fd760e6067b361fdb9e3a5d 100644 (file)
@@ -2868,9 +2868,9 @@ class PGDDLCompiler(compiler.DDLCompiler):
             if not isinstance(inherits, (list, tuple)):
                 inherits = (inherits,)
             table_opts.append(
-                "\n INHERITS ( "
+                "\n INHERITS ("
                 + ", ".join(self.preparer.quote(name) for name in inherits)
-                + " )"
+                + ")"
             )
 
         if pg_opts["partition_by"]:
index 867e1f3686c179201c983ee638ded7ad5ff351e9..2570bbe9018908ec6d2581340ab9657b6ef5f55c 100644 (file)
@@ -502,7 +502,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
         )
         self.assert_compile(
             schema.CreateTable(tbl),
-            "CREATE TABLE atable (id INTEGER) INHERITS ( i1 )",
+            "CREATE TABLE atable (id INTEGER) INHERITS (i1)",
         )
 
     def test_create_table_inherits_tuple(self):
@@ -515,7 +515,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
         )
         self.assert_compile(
             schema.CreateTable(tbl),
-            "CREATE TABLE atable (id INTEGER) INHERITS ( i1, i2 )",
+            "CREATE TABLE atable (id INTEGER) INHERITS (i1, i2)",
         )
 
     def test_create_table_inherits_quoting(self):
@@ -529,7 +529,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
         self.assert_compile(
             schema.CreateTable(tbl),
             "CREATE TABLE atable (id INTEGER) INHERITS "
-            '( "Quote Me", "quote Me Too" )',
+            '("Quote Me", "quote Me Too")',
         )
 
     def test_create_table_inherits_schema_qualified_quoted_name(self):
@@ -545,7 +545,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
         self.assert_compile(
             schema.CreateTable(tbl),
             "CREATE TABLE atable (id INTEGER) "
-            "INHERITS ( my_schema.parent_table )",
+            "INHERITS (my_schema.parent_table)",
         )
 
     def test_create_table_partition_by_list(self):