Skip to content

sql: add bounds checking for trig functions#168717

Merged
trunk-io[bot] merged 1 commit intocockroachdb:masterfrom
bghal:sql-trig-input
May 7, 2026
Merged

sql: add bounds checking for trig functions#168717
trunk-io[bot] merged 1 commit intocockroachdb:masterfrom
bghal:sql-trig-input

Conversation

@bghal
Copy link
Copy Markdown
Contributor

@bghal bghal commented Apr 20, 2026

The previous behavior of returning NaN was
inconsistent with PG and may have caused
downstream errors. The forward trig functions
weren't rejecting infinity as input which is also
inconsistent with PG.

Epic: none
Fixes: #168595

Release note (bug fix): Trig functions passed out-of-range input now
return errors consistent with PostgreSQL.

@bghal bghal requested a review from a team as a code owner April 20, 2026 19:17
@trunk-io
Copy link
Copy Markdown
Contributor

trunk-io Bot commented Apr 20, 2026

😎 Merged successfully - details.

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Collaborator

@fqazi fqazi left a comment

Choose a reason for hiding this comment

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

:lgtm:

@fqazi reviewed 3 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on bghal).

Copy link
Copy Markdown
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

nice find! acosh and atanh have the identical NaN-instead-of-error bug in CRDB and postgres rejects them too. can we fix them now?

@rafiss made 2 comments.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on bghal).


-- commits line 11 at r1:
for this to get categorized properly, it should say Release note (bug fix)

@bghal bghal force-pushed the sql-trig-input branch 3 times, most recently from fa46206 to 4db389e Compare April 24, 2026 21:37
Copy link
Copy Markdown
Contributor Author

@bghal bghal left a comment

Choose a reason for hiding this comment

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

Done.

@bghal made 2 comments.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on fqazi and rafiss).


-- commits line 11 at r1:

Previously, rafiss (Rafi Shamim) wrote…

for this to get categorized properly, it should say Release note (bug fix)

Done.

@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented Apr 24, 2026

Detected infrastructure failure (matched: self-hosted runner lost communication with the server). Automatically rerunning failed jobs. (run link)

@bghal bghal requested a review from rafiss April 27, 2026 15:09
Copy link
Copy Markdown
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

@rafiss made 1 comment.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on bghal and fqazi).


pkg/sql/sem/eval/testdata/eval/trig line 172 at r2 (raw file):


eval
atanh(1)

this is overly strict. PG allows inputs in the range of [-1, 1] (inclusive bounds)

postgres=# select atanh(1.0);
  atanh
----------
 Infinity
(1 row)

postgres=# select atanh(-1.0);
   atanh
-----------
 -Infinity
(1 row)

please fix this and double check the other functions validation. tip: you don't need to do this manually. ask claude to look at the postgres source code. (you can clone the repo locally onto your own machine so it doesn't have to do slow network operations.)

@bghal bghal force-pushed the sql-trig-input branch 2 times, most recently from 8f92217 to cb2771e Compare May 5, 2026 15:07
@bghal bghal changed the title sql: error on out-of-range input to trig functions sql: add bounds checking for trig functions May 5, 2026
@bghal bghal force-pushed the sql-trig-input branch 3 times, most recently from b8d1752 to e17fe53 Compare May 7, 2026 17:43
The previous behavior of returning NaN was
inconsistent with PG and may have caused
downstream errors. The forward trig functions
weren't rejecting infinity as input which is also
inconsistent with PG.

Epic: none
Fixes: cockroachdb#168595

Release note (bug fix): Trig functions passed out-of-range input now
return errors consistent with PostgreSQL.
@rafiss rafiss force-pushed the sql-trig-input branch from e17fe53 to f840c38 Compare May 7, 2026 18:25
Copy link
Copy Markdown
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

lgtm!

/trunk merge

@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented May 7, 2026

Detected infrastructure failure (matched: self-hosted runner lost communication with the server). Automatically rerunning failed jobs. (run link)

@trunk-io trunk-io Bot merged commit 5a85bc6 into cockroachdb:master May 7, 2026
37 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql: invalid argument to asin(), acosd(), and asind() results in NaN instead of error

4 participants