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

add null checks in type cast methods #398

Merged
merged 3 commits into from
Jun 20, 2024
Merged

add null checks in type cast methods #398

merged 3 commits into from
Jun 20, 2024

Conversation

jennifersp
Copy link
Contributor

No description provided.

@jennifersp jennifersp linked an issue Jun 17, 2024 that may be closed by this pull request
@jennifersp jennifersp linked an issue Jun 17, 2024 that may be closed by this pull request
@jennifersp jennifersp requested a review from Hydrocharged June 17, 2024 19:25
Copy link
Collaborator

@Hydrocharged Hydrocharged left a comment

Choose a reason for hiding this comment

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

We didn't do this for the normal functions, but instead of adding null checks to all of the cast functions, we should implement the actual null handling for functions.

https://www.postgresql.org/docs/15/sql-createfunction.html

In particular, CALLED ON NULL INPUT, RETURNS NULL ON NULL INPUT, and STRICT. We shouldn't necessarily do that on this PR though, since we also need to shift casts to the general function structure (like how we handle operators and comparisons). Instead, for this PR, since we know all of the casts use RETURNS NULL ON NULL INPUT (same as STRICT), we can simply add the null check before we call the cast function, so that it works for every cast.

For reference, this query looks at pg_proc for all cast functions, and we check the proisstrict column to determine whether a function is STRICT or not, so you can use this to check how any function is supposed to handle nulls.

SELECT pg_proc.* FROM pg_proc JOIN pg_cast ON pg_proc.oid = pg_cast.castfunc;

@jennifersp jennifersp force-pushed the jennifer/cast-null branch from cc9ec2d to f1bd08d Compare June 18, 2024 22:15
@jennifersp jennifersp requested a review from Hydrocharged June 18, 2024 22:28
Copy link
Collaborator

@Hydrocharged Hydrocharged left a comment

Choose a reason for hiding this comment

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

LGTM! Just need to readjust the location of the strict check

server/functions/framework/compiled_function.go Outdated Show resolved Hide resolved
@jennifersp jennifersp enabled auto-merge (squash) June 20, 2024 16:31
@jennifersp jennifersp merged commit 5aa4696 into main Jun 20, 2024
9 checks passed
@jennifersp jennifersp deleted the jennifer/cast-null branch June 20, 2024 18:58
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.

SQL Correctness harness broken
2 participants