Opened 14 years ago

Last modified 13 years ago

#13826 closed

Impossible to create indexes on PostGIS fields — at Initial Version

Reported by: aneil Owned by: nobody
Component: GIS Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

I've included a patch which addresses the request below. This adds a signal, final_post_syncdb which enables adding sql commands after all custom sql and indexes and PostGIS columns are created. The patch is with respect to django-trunk

  • * *

Please add a "final_post_syncdb" signal. See http://code.djangoproject.com/ticket/7561.

It is currently not possible to add custom SQL which depends on GeoDjango fields. This is because the custom sql appears before the commands which create the PostGIS column.

For example, I'd like to create a multicolumn GiST index on Postgres:

in myapp.models.py:

class Location(Model):
   counter = IntegerField() 
   point = PointField()

in sql/location.sql:

    CREATE INDEX idx_location_point_counter ON main_location USING GIST(point,counter);

results in the error:
Failed to install custom SQL for main.Location model: column "point" does not exist

(Note, that on Postgres, one needs to install contrib/btree_gist.sql to enable GiST indexes on integer fields)

./manage.py sqlall main yields:

CREATE TABLE "main_location" (
    "id" serial NOT NULL PRIMARY KEY,
    "counter" integer
)
;
CREATE INDEX idx_location_point_counter ON main_location USING GIST(point,counter);
SELECT AddGeometryColumn('main_location', 'point', 4326, 'POINT', 2); 

The problem is in the last two lines: the sql refers to the point column before it's created.

Unfortunately, the post_syncdb signal is no help either, since this is also sent before the PostGIS commands are generated.

Change History (1)

by aneil, 14 years ago

Attachment: final_post_sync.diff added
Note: See TracTickets for help on using tickets.
Back to Top