postgrespro / pgsphere

PgSphere provides spherical data types, functions, operators, and indexing for PostgreSQL.
https://pgsphere.org
BSD 3-Clause "New" or "Revised" License
16 stars 15 forks source link

Missing equality operator for type spoint? #101

Closed esabol closed 7 months ago

esabol commented 8 months ago
# select distinct spoint_deg(lon, lat) from sometable;
ERROR:  could not identify an equality operator for type spoint

I think this is a reasonable thing to do?

Should equality operators for the pgsphere types be added?

df7cb commented 8 months ago

spoint = spoint does exist, but what this message means is that we'd need a spoint btree or hash opclass. I'll cook something up.

esabol commented 8 months ago

Would it similarly make sense to add hash opclasses for the other pgsphere types (strans, scircle, spoly)? Probably not as useful as spoint, but for the sake of completeness?

df7cb commented 8 months ago

It's (sort of) easy for the types that have canonical representations. scircle is doable, but spoly would need sorting the nodes, and I hear there's open issues with left- and right-handed spolys.

That said, there's a possible minor problem even with spoints: the dreaded "signed zeros" might cause "equal" spoints to have representations differing in the sign. But that only applies to spoints where one coordinate is exactly zero, no idea how likely that is in practise. We might also force all zeros to be +0 either in spoint_hash32 or in spoint_in.

Which types would you be interested in?

msdemlei commented 8 months ago

On Fri, Nov 03, 2023 at 12:25:40PM -0700, Christoph Berg wrote:

representations differing in the sign. But that only applies to spoints where one coordinate is exactly zero, no idea how likely that is in practise. We might also force all zeros to be +0

Regrettably, exactly zero happens a lot more often than one would expect – not because nature had some unnatural preference, but because points on coordinate axes are perennial favourites for tests, artificial data, and the lot. And that's not exclusively lazyness, since often it's a lot easier to figure out results manually when you are on an axis.

So, if there's odd behaviour on the axes, that's probably harmless for physics but potentially hazardous for development.

esabol commented 8 months ago

@df7cb asked:

Which types would you be interested in?

Hard to say. I could see using an scircle hash opclass.

I wonder if the error in issue #93 would be helped if there was a hash opclass for strans?

Also, I'm ok with forcing all zeroes to be +0 in the spoint hash function if that "solves" any problems you foresee.