patito.duckdb.Relation.create_table

Relation.create_table(name)

Create new database table based on relation.

If self.model is set with Relation.set_model(), then the model is used to infer the table schema. Otherwise, a permissive table schema is created based on the relation data.

Returns:

A relation pointing to the newly created table.

Return type:

Relation

Examples

>>> from typing import Literal
>>> import patito as pt
>>> df = pt.DataFrame({"enum_column": ["A", "A", "B"]})
>>> relation = pt.duckdb.Relation(df)
>>> relation.create_table("permissive_table").types
{'enum_column': VARCHAR}
>>> class TableSchema(pt.Model):
...     enum_column: Literal["A", "B", "C"]
...
>>> relation.set_model(TableSchema).create_table("strict_table").types
{'enum_column': enum__7ba49365cc1b0fd57e61088b3bc9aa25}