Skip to main content

PostgresIndex

This class provides a base implementation for PostgreSQL-specific database indexes, extending standard index functionality with support for custom storage parameters and access methods. It manages the generation of SQL statements using the USING and WITH clauses while allowing for index names that exceed standard cross-database length constraints. The class also includes mechanisms to verify PostgreSQL installation and feature support during index creation.

Methods


max_name_length()

@classmethod
def max_name_length() - > int

Calculates the maximum allowed length for the index name, adjusting the standard limit to accommodate PostgreSQL-specific suffixes.

Returns

TypeDescription
intThe maximum number of characters allowed for the index name.

create_sql()

@classmethod
def create_sql(
model: django.db.models.Model,
schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor,
using: string
) - > django.db.backends.utils.CursorDebugWrapper

Generates the SQL statement required to create the index on the database, including PostgreSQL-specific 'USING' and 'WITH' clauses.

Parameters

NameTypeDescription
modeldjango.db.models.ModelThe model class that the index is being applied to.
schema_editordjango.db.backends.base.schema.BaseDatabaseSchemaEditorThe database abstraction layer used to apply schema changes.
usingstringThe index method to use, such as GIN or GiST; defaults to the class suffix if not provided.

Returns

TypeDescription
django.db.backends.utils.CursorDebugWrapperA statement object containing the formatted SQL and parameters for index creation.

check_supported()

@classmethod
def check_supported(
schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor
) - > null

Validates if the current database backend and version support the specific features required by this index type.

Parameters

NameTypeDescription
schema_editordjango.db.backends.base.schema.BaseDatabaseSchemaEditorThe schema editor instance used to check database engine compatibility.

Returns

TypeDescription
null

get_with_params()

@classmethod
def get_with_params() - > list

Retrieves a list of storage parameters to be included in the 'WITH' clause of the index creation statement.

Returns

TypeDescription
listA list of strings representing index storage parameters like 'fillfactor'.