Skip to content

Add missing PostgreSQL operators and fix >^ geometric operator#938

Merged
nene merged 1 commit intosql-formatter-org:masterfrom
beekeeper-studio:fix/postgresql-missing-operators
Mar 28, 2026
Merged

Add missing PostgreSQL operators and fix >^ geometric operator#938
nene merged 1 commit intosql-formatter-org:masterfrom
beekeeper-studio:fix/postgresql-missing-operators

Conversation

@rathboma
Copy link
Copy Markdown
Contributor

Summary

  • Adds support for 5 PostgreSQL operators from core and popular extensions that were incorrectly tokenized (split into shorter operators): <@> (earthdistance), &&& (PostGIS 3D overlap), |=| (PostGIS trajectory distance), ~> (cube), #= (hstore)
  • Fixes the geometric "is above" operator which was defined as ^> instead of >^ per PostgreSQL docs
  • Adds unit tests for each operator in realistic SQL contexts, with links to relevant PostgreSQL/PostGIS documentation

Detail

The formatter's tokenizer was greedily matching shorter known operators instead of the full operator. For example <@> was being split into <@ + >, producing bar <@ > point(1, 2) instead of bar <@> point(1, 2).

The fix is simply adding these operators to the PostgreSQL dialect's operator list. The existing regex builder in regexFactory.ts already sorts operators by length descending, so longer operators automatically take priority.

Operators added

Operator Source Docs
<@> earthdistance extension earthdistance
&&& PostGIS geometry_overlaps_nd
|=| PostGIS geometry_distance_cpa
~> cube extension cube
#= hstore extension hstore
>^ (fix) geometric functions-geometry

Test plan

  • All new operators tested via supportsOperators() for basic spacing and dense mode
  • All new operators tested in realistic SQL contexts (WHERE, ORDER BY, SELECT)
  • Full PostgreSQL test suite passes (460 tests)

Adds support for several PostgreSQL operators from core and popular
extensions that were previously being split into shorter tokens:

- <@> (earthdistance distance)
- &&& (PostGIS 3D bounding box overlap)
- |=| (PostGIS closest point of approach distance)
- ~> (cube coordinate extraction)
- #= (hstore replace fields)

Also fixes the geometric "is above" operator which was incorrectly
defined as ^> instead of >^ per the PostgreSQL docs.
@codesandbox-ci
Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@nene
Copy link
Copy Markdown
Collaborator

nene commented Mar 28, 2026

Well, thanks, I appreciate the fixes.

I however do not appreciate the LLM-written pull request description. Really, my first reaction was to just reject this whole pull request because it has LLM written all over it and why should I bother reading and understanding all that LLM written text and code if you didn't bother to give any sort of human touch to it. Please don't do this in the future. It's really just not nice towards open source maintainers.

);
});

// Tests for PostgreSQL containment and full-text search operators
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these additional "operator tests in context" here are unnecessary. It's just noise, with no real value.

Comment on lines +322 to +341
'&&&',
'&<',
'&>',
'<<|',
'&<|',
'|>>',
'|&>',
'<^',
'^>',
'>^',
'?#',
'?-',
'?|',
'?-|',
'?||',
'@>',
'<@',
'<@>',
'~=',
// PostGIS
'|=|',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the PR summary the &&& operator and |=| are listed as PostGIS operators, but in the actual code only the latter is placed to PostGIS group. Some consistency would be nice.

});
});

// Tests for extension operators (hstore, cube, ltree)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From where does the ltree come into play?

});

// https://www.postgresql.org/docs/current/functions-geometry.html
// Note: the formatter defines ^> but PostgreSQL docs say the operator is >^
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it defined ^> in the past, but now after this PR it's corrected. So the comment doesn't really make sense any more.

@nene nene merged commit a45ab63 into sql-formatter-org:master Mar 28, 2026
2 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.

2 participants