Several options for CREATE TABLE are supported directly by the PostgreSQL
dialect in conjunction with the :class:`_schema.Table` construct:
-* ``TABLESPACE``::
+* ``INHERITS``::
- Table("some_table", metadata, ..., postgresql_tablespace='some_tablespace')
+ Table("some_table", metadata, ..., postgresql_inherits="some_supertable")
- The above option is also available on the :class:`.Index` construct.
+ Table("some_table", metadata, ..., postgresql_inherits=("t1", "t2", ...))
* ``ON COMMIT``::
Table("some_table", metadata, ..., postgresql_on_commit='PRESERVE ROWS')
-* ``WITH OIDS``::
+* ``PARTITION BY``::
- Table("some_table", metadata, ..., postgresql_with_oids=True)
+ Table("some_table", metadata, ...,
+ postgresql_partition_by='LIST (part_column)')
-* ``WITHOUT OIDS``::
+ .. versionadded:: 1.2.6
- Table("some_table", metadata, ..., postgresql_with_oids=False)
+* ``TABLESPACE``::
-* ``INHERITS``::
+ Table("some_table", metadata, ..., postgresql_tablespace='some_tablespace')
- Table("some_table", metadata, ..., postgresql_inherits="some_supertable")
+ The above option is also available on the :class:`.Index` construct.
- Table("some_table", metadata, ..., postgresql_inherits=("t1", "t2", ...))
+* ``USING``::
-* ``PARTITION BY``::
+ Table("some_table", metadata, ..., postgresql_using='heap')
- Table("some_table", metadata, ...,
- postgresql_partition_by='LIST (part_column)')
+ .. versionadded:: 2.0.26
- .. versionadded:: 1.2.6
+* ``WITH OIDS``::
+
+ Table("some_table", metadata, ..., postgresql_with_oids=True)
+
+* ``WITHOUT OIDS``::
+
+ Table("some_table", metadata, ..., postgresql_with_oids=False)
.. seealso::
if pg_opts["partition_by"]:
table_opts.append("\n PARTITION BY %s" % pg_opts["partition_by"])
+ if pg_opts["using"]:
+ table_opts.append("\n USING %s" % pg_opts["using"])
+
if pg_opts["with_oids"] is True:
table_opts.append("\n WITH OIDS")
elif pg_opts["with_oids"] is False:
"with_oids": None,
"on_commit": None,
"inherits": None,
+ "using": None,
},
),
(
"CREATE TABLE atable (id INTEGER) ON COMMIT DROP",
)
+ def test_create_table_with_using_option(self):
+ m = MetaData()
+ tbl = Table(
+ "atable",
+ m,
+ Column("id", Integer),
+ postgresql_using="heap",
+ )
+ self.assert_compile(
+ schema.CreateTable(tbl),
+ "CREATE TABLE atable (id INTEGER) USING heap",
+ )
+
def test_create_table_with_multiple_options(self):
m = MetaData()
tbl = Table(
postgresql_tablespace="sometablespace",
postgresql_with_oids=False,
postgresql_on_commit="preserve_rows",
+ postgresql_using="heap",
)
self.assert_compile(
schema.CreateTable(tbl),
- "CREATE TABLE atable (id INTEGER) WITHOUT OIDS "
+ "CREATE TABLE atable (id INTEGER) USING heap WITHOUT OIDS "
"ON COMMIT PRESERVE ROWS TABLESPACE sometablespace",
)