]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Adding oids and on_commit table options
authorMalik Diarra <malik.diarra@gmail.com>
Sat, 16 Aug 2014 22:39:36 +0000 (00:39 +0200)
committerMalik Diarra <malik.diarra@gmail.com>
Sat, 16 Aug 2014 23:56:02 +0000 (01:56 +0200)
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/postgresql/test_compiler.py

index 0f008642e8294aa8fd86ccb089b998d707e9d75c..9b30bf8949c0289e94b5c820cf484aea70199a14 100644 (file)
@@ -1450,6 +1450,14 @@ class PGDDLCompiler(compiler.DDLCompiler):
 
     def post_create_table(self, table):
         table_opts = []
+        if table.dialect_options['postgresql']['withoids'] is not None:
+            if table.dialect_options['postgresql']['withoids']:
+                table_opts.append('WITH OIDS')
+            else:
+                table_opts.append('WITHOUT OIDS')
+        if table.dialect_options['postgresql']['on_commit']:
+            on_commit_options = table.dialect_options['postgresql']['on_commit'].replace("_", " ").upper()
+            table_opts.append('ON COMMIT %s' % on_commit_options) 
         if table.dialect_options['postgresql']['tablespace']:
             table_opts.append('TABLESPACE %s' % table.dialect_options['postgresql']['tablespace'])
 
@@ -1715,7 +1723,9 @@ class PGDialect(default.DefaultDialect):
         }),
         (schema.Table, {
             "ignore_search_path": False,
-            "tablespace": None
+            "tablespace": None,
+            "withoids" : None,
+            "on_commit" : None,
         })
     ]
 
index 301f80fd4408a261e70a428e4704a6702a5e91b9..b439ab916fc325c6f27d325ed6e3210a62bea40c 100644 (file)
@@ -172,6 +172,28 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
         self.assert_compile(schema.CreateTable(tbl),
                 "CREATE TABLE atable (id INTEGER)TABLESPACE sometablespace")
 
+    def test_create_table_with_oids(self):
+        m = MetaData()
+        tbl = Table('atable', m, Column("id", Integer), postgresql_withoids = True, )
+        self.assert_compile(schema.CreateTable(tbl),
+                "CREATE TABLE atable (id INTEGER)WITH OIDS")
+
+        tbl2 = Table('anothertable', m, Column("id", Integer), postgresql_withoids = False, )
+        self.assert_compile(schema.CreateTable(tbl2),
+                "CREATE TABLE anothertable (id INTEGER)WITHOUT OIDS")
+
+    def create_table_with_oncommit_option(self):
+        m = MetaData()
+        tbl = Table('atable', m, Column("id", Integer), postgresql_on_commit = "drop")
+        self.assert_compile(schema.CreateTable(tbl),
+                "CREATE TABLE atable (id INTEGER) ON COMMIT DROP")
+    
+    def create_table_with_multiple_options(self):
+        m = MetaData()
+        tbl = Table('atable', m, Column("id", Integer), postgresql_tablespace = 'sometablespace', postgresql_withoids = False, postgresql_on_commit = "preserve_rows")
+        self.assert_compile(schema.CreateTable(tbl),
+                "CREATE TABLE atable (id INTEGER)WITHOUT OIDS ON COMMIT PRESERVE ROWS TABLESPACE sometablespace")
+    
     def test_create_partial_index(self):
         m = MetaData()
         tbl = Table('testtbl', m, Column('data', Integer))