Skip to content

[12.x] Add operator class support for PostgreSQL GiST spatial indexes #56324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2025

Conversation

joteejotee
Copy link
Contributor

This PR adds support for specifying operator classes when creating spatial indexes on PostgreSQL, addressing issue #56261.

Problem

PostgreSQL GiST indexes require explicit operator classes for certain data types (like inet). Currently, Laravel's spatialIndex() method doesn't support specifying operator classes, causing migrations to fail with:

ERROR: data type inet has no default operator class for access method "gist"

Solution

Add an optional $operatorClass parameter to Blueprint::spatialIndex():

// Before (fails for inet)
$table->spatialIndex(['coordinates']);

// After (works with operator class)
$table->spatialIndex(['coordinates'], 'my_index', 'point_ops');
$table->spatialIndex(['client_internet'], 'inet_idx', 'inet_ops');

Changes

  • Add optional $operatorClass parameter to Blueprint::spatialIndex()
  • Update PostgresGrammar::compileSpatialIndex() to handle operator classes
  • Add comprehensive tests for the new functionality
  • Maintain full backward compatibility

Fixes #56261

This change allows specifying an operator class when creating spatial indexes
on PostgreSQL, which is required for certain data types like inet.

- Add optional operatorClass parameter to Blueprint::spatialIndex()
- Update PostgresGrammar to handle operator class in SQL generation
- Add tests for spatial index with operator class functionality

Fixes laravel#56261
@taylorotwell taylorotwell merged commit 1784f2e into laravel:12.x Jul 18, 2025
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Operator Class for PostgreSQL GiST-Index required
2 participants