A DDL-specified DEFAULT column value. :class:`.DefaultClause` is a :class:`.FetchedValue` that also generates a "DEFAULT" clause when "CREATE TABLE" is emitted. :class:`.DefaultClause` is generated automatically whenever the ``server_default``, ``server_onupdate`` arguments of
| 4413 | |
| 4414 | |
| 4415 | class DefaultClause(FetchedValue): |
| 4416 | """A DDL-specified DEFAULT column value. |
| 4417 | |
| 4418 | :class:`.DefaultClause` is a :class:`.FetchedValue` |
| 4419 | that also generates a "DEFAULT" clause when |
| 4420 | "CREATE TABLE" is emitted. |
| 4421 | |
| 4422 | :class:`.DefaultClause` is generated automatically |
| 4423 | whenever the ``server_default``, ``server_onupdate`` arguments of |
| 4424 | :class:`_schema.Column` are used. A :class:`.DefaultClause` |
| 4425 | can be passed positionally as well. |
| 4426 | |
| 4427 | For example, the following:: |
| 4428 | |
| 4429 | Column("foo", Integer, server_default="50") |
| 4430 | |
| 4431 | Is equivalent to:: |
| 4432 | |
| 4433 | Column("foo", Integer, DefaultClause("50")) |
| 4434 | |
| 4435 | """ |
| 4436 | |
| 4437 | has_argument = True |
| 4438 | |
| 4439 | def __init__( |
| 4440 | self, |
| 4441 | arg: Union[str, ClauseElement, TextClause], |
| 4442 | for_update: bool = False, |
| 4443 | _reflected: bool = False, |
| 4444 | ) -> None: |
| 4445 | util.assert_arg_type(arg, (str, ClauseElement, TextClause), "arg") |
| 4446 | super().__init__(for_update) |
| 4447 | self.arg = arg |
| 4448 | self.reflected = _reflected |
| 4449 | |
| 4450 | @util.memoized_property |
| 4451 | @util.preload_module("sqlalchemy.sql.functions") |
| 4452 | def _is_monotonic_fn(self) -> bool: |
| 4453 | functions = util.preloaded.sql_functions |
| 4454 | return ( |
| 4455 | isinstance(self.arg, functions.FunctionElement) |
| 4456 | and self.arg.monotonic |
| 4457 | ) |
| 4458 | |
| 4459 | def _copy(self) -> DefaultClause: |
| 4460 | return DefaultClause( |
| 4461 | arg=self.arg, for_update=self.for_update, _reflected=self.reflected |
| 4462 | ) |
| 4463 | |
| 4464 | def __repr__(self) -> str: |
| 4465 | return "DefaultClause(%r, for_update=%r)" % (self.arg, self.for_update) |
| 4466 | |
| 4467 | |
| 4468 | class Constraint(DialectKWArgs, HasConditionalDDL, SchemaItem): |
no outgoing calls