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

CASE-WHEN branches are not typed per SQL-99 rules. #1390

Closed
RCHowell opened this issue Mar 14, 2024 · 0 comments
Closed

CASE-WHEN branches are not typed per SQL-99 rules. #1390

RCHowell opened this issue Mar 14, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@RCHowell
Copy link
Member

Description

The current implementation of PartiQL (0.14) added static typing to queries, but the CASE-WHEN does not follow SQL-99 when branches have a minimal common supertype.

We expect CASE-WHEN to follow SQL-99 9.3 Data types of results of aggregations which defines how a CASE-WHEN should be typed.

To Reproduce

Steps to reproduce the behavior:

Consider two exact-numeric return values

 CASE
   WHEN a = 'hello' THEN 0
   ELSE 1.0
END

-- type
-- decimal | int32

Expected Behavior

SQL-99 defines the coercion rules of the output types of a CASE-WHEN. We expect this to be typed as just decimal

If all of the data types in DTS are exact numeric, then the result data type is exact numeric
with implementation-defined precision and with scale equal to the maximum of the scales of
the data types in DTS

For heterogenous data, PartiQL uses the dynamic type as the minimal common supertype

Otherwise, there shall exist a subtype family STF such that each data type in DTS is a
member of STF. The result data type is the minimal common supertype of each data type in
DTS.

This enables PartiQL to behave like ANSI SQL while still handling heterogenous branch types.

Additional Context

  • Java version: 11
  • PartiQL version: 0.14.3
  • Add any other context about the problem here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant