On 12/17/22 20:40, Martin L. Buchanan
wrote:
Dear Rob and all readers:
Generating prime numbers is one example where you use integer square root in the inner loop, going from integer to integer.
Calculating an integer square root from an integer input may have a more efficient algorithm than doing so in floating-point, with the caveat that an underlying processor architecture may provide floating-point square root instructions but not integer square root instructions. In that particular case an implementation could use the floating-point instructions internally.
Some but not all programming languages provide isqrt directly, math.isqrt in Python or isqrt in Common Lisp for example.
It would be a useful and convenient function and would not, I believe, impair the other features of PostgreSQL in any way.
That said, as a PG novice (2+ years now), I completely defer to the greater wisdom of those much more involved in PostgreSQL. So something for you all to think about.
Seasons greetings to you and welcome to the list. Here we generally bottom post.
I have zero say in whether or not isqrt might get added to postgres but in the meantime you might craft your own function (sql or plpgsql) which does the necessary casting. Or are you specifically after a faster function? And would a plpythonu function using their isqrt be fast enough. (Note the "u" in plpythonu means "untrusted")