Databases
sql.postgres.ddl
import sql.postgres.ddl
Zuri
sqldoes not re-export this module, so it is reached only by importing it directly.
Schema changes for PostgreSQL.
PostgreSQL can make every change a blueprint describes with a plain statement, and it rolls back schema changes along with the transaction they ran in, so a migration that fails partway through leaves nothing behind.
An id() is an identity column, generated by default, so a row can
still be inserted with an ID of its own. When a column changes type, its
values are converted with a cast from the old type, so a text column
holding numbers can become a number column.
Classes
PostgresDdl
class sql.postgres.ddl.PostgresDdl < DdlAdapter
ZuriTurns blueprints into PostgreSQL's statements.
PostgresDdl.type_name()
sql.postgres.ddl.PostgresDdl.type_name(column) -> string
ZuriParameters
column(Column)
Returns string
PostgresDdl.key_definition()
sql.postgres.ddl.PostgresDdl.key_definition(column) -> string
ZuriParameters
column(Column)
Returns string
PostgresDdl.exact_collation()
sql.postgres.ddl.PostgresDdl.exact_collation() -> string
ZuriReturns string
PostgresDdl.string_literal()
sql.postgres.ddl.PostgresDdl.string_literal(text: string) -> string
ZuriA string as a literal. One holding a backslash is written as an escape
string with the backslash doubled, which means the same whatever
standard_conforming_strings is set to.
Parameters
text(string)
Returns string
PostgresDdl.change_column()
sql.postgres.ddl.PostgresDdl.change_column(connection, table: string, column) -> list[string]
ZuriThe change, as one alter table with an action for each part of the
definition. The default is dropped first and set again last, so a
default of the old type never has to survive the cast.
Parameters
connection(Connection)table(string)column(Column)
Returns list[string]
PostgresDdl.drop_primary()
sql.postgres.ddl.PostgresDdl.drop_primary(connection, table: string) -> list[string]
ZuriParameters
connection(Connection)table(string)
Returns list[string]
Raises QueryError if the table has no primary key.
PostgresDdl.migration_lock()
sql.postgres.ddl.PostgresDdl.migration_lock(connection, name: string, body: function) -> any
ZuriHolds a session advisory lock keyed by name while body runs, waiting
for another session holding it to let go.
Parameters
connection(Connection)name(string)body(function)
Returns any — What body returned.
2026, Richard Ore and Zuri contributors