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
| Type | Description |
|---|---|
int | The 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
| Name | Type | Description |
|---|---|---|
| model | django.db.models.Model | The model class that the index is being applied to. |
| schema_editor | django.db.backends.base.schema.BaseDatabaseSchemaEditor | The database abstraction layer used to apply schema changes. |
| using | string | The index method to use, such as GIN or GiST; defaults to the class suffix if not provided. |
Returns
| Type | Description |
|---|---|
django.db.backends.utils.CursorDebugWrapper | A 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
| Name | Type | Description |
|---|---|---|
| schema_editor | django.db.backends.base.schema.BaseDatabaseSchemaEditor | The schema editor instance used to check database engine compatibility. |
Returns
| Type | Description |
|---|---|
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
| Type | Description |
|---|---|
list | A list of strings representing index storage parameters like 'fillfactor'. |