Skip to content
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

Additional spoly constructors? #95

Closed
esabol opened this issue Oct 27, 2023 · 5 comments
Closed

Additional spoly constructors? #95

esabol opened this issue Oct 27, 2023 · 5 comments

Comments

@esabol
Copy link
Contributor

esabol commented Oct 27, 2023

The spoly_deg() function can construct a spoly from an array of float8:

CREATE FUNCTION spoly_deg(float8[])
   RETURNS spoly
   AS 'MODULE_PATHNAME', 'spherepoly_deg'
   LANGUAGE 'c'
   IMMUTABLE STRICT;

(Aside: Why is this function not PARALLEL SAFE? Should it be?)

But there's no corresponding spoly constructor that takes an array of float8 in radians:

testdb=> SELECT spoly(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
ERROR:  function spoly(numeric[]) does not exist
LINE 1: SELECT spoly(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

I don't want to use a temporary table to construct a spoly in my PLpgsql functions. It's horribly inefficient and doesn't scale when operating over very large tables. So that means I have to either convert my coordinates to degrees (only for spherepoly_deg() to convert them back to radians) in order to avoid that or construct a string to contain the array of coordinates and use the spoly constructor on the string.

Also, I think it would be nice if there was a constructor that takes an array of spoint as well, so that you can do this:

SELECT spoly([spoint(1.0, 2.0), spoint(3.0, 4.0), spoint(5.0, 6.0)]);

Should that be possible? What do you think?

@vitcpp
Copy link
Contributor

vitcpp commented Oct 30, 2023

@esabol I think, it is possible what you proposes. Postgresql supports function overloading.

I propose to complete your PR and then try to implement spoly(spoint[]) as another PR.

@esabol
Copy link
Contributor Author

esabol commented Oct 31, 2023

How would you advise implementing the spoly(spoint[]) constructor function?

Would the spoint array need to be duplicated in memory (using the equivalent of a copy constructor)? Or can you reuse the same array and/or the same array members passed in as arguments?

@esabol
Copy link
Contributor Author

esabol commented Oct 31, 2023

It feels like there should be some trick to creating an spoly from an array of spoints since you can sort of already do the following in PLpgsql:

select spoly(t.pnt)
  into thepoly 
  from (select pnt from xxxpnts order by ord) as t;

@vitcpp
Copy link
Contributor

vitcpp commented Oct 31, 2023

How would you advise implementing the spoly(spoint[]) constructor function?

I will propose an implementation. May be tomorrow.

@vitcpp
Copy link
Contributor

vitcpp commented Nov 7, 2023

@esabol esabol closed this as completed Nov 8, 2023
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

No branches or pull requests

2 participants