TableAlterer
deltalake.table.TableAlterer
API for various table alteration commands.
add_constraint
add_constraint(constraints: Dict[str, str], custom_metadata: Optional[Dict[str, str]] = None) -> None
Add constraints to the table. Limited to single constraint
at once.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
constraints |
Dict[str, str]
|
mapping of constraint name to SQL-expression to evaluate on write |
required |
custom_metadata |
Optional[Dict[str, str]]
|
custom metadata that will be added to the transaction commit. |
None
|
Example:
from deltalake import DeltaTable
dt = DeltaTable("test_table_constraints")
dt.alter.add_constraint({
"value_gt_5": "value > 5",
})
**Check configuration**
```
dt.metadata().configuration
{'delta.constraints.value_gt_5': 'value > 5'}
```
drop_constraint
drop_constraint(name: str, raise_if_not_exists: bool = True, custom_metadata: Optional[Dict[str, str]] = None) -> None
Drop constraints from a table. Limited to single constraint
at once.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
constraint name which to drop. |
required |
raise_if_not_exists |
bool
|
set if should raise if not exists. |
True
|
custom_metadata |
Optional[Dict[str, str]]
|
custom metadata that will be added to the transaction commit. |
None
|
Example:
from deltalake import DeltaTable
dt = DeltaTable("test_table_constraints")
dt.metadata().configuration
{'delta.constraints.value_gt_5': 'value > 5'}
**Drop the constraint**
```python
dt.alter.drop_constraint(name = "value_gt_5")
```
**Configuration after dropping**
```python
dt.metadata().configuration
{}
```