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

sql result discrepency with sqlite and postgres #13779

Open
Tracked by #13811
Omega359 opened this issue Dec 14, 2024 · 1 comment
Open
Tracked by #13811

sql result discrepency with sqlite and postgres #13779

Omega359 opened this issue Dec 14, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Omega359
Copy link
Contributor

Describe the bug

sqlite random/expr/slt_good_10.slt:

SELECT ALL + + MIN ( - CAST ( + 6 AS INTEGER ) ) * CASE WHEN NULL BETWEEN - 88 AND ( - - 91 ) * - AVG ( 95 ) THEN COUNT ( - 34 ) END

Both PG and sqlite have a result of 'null'. DF result is '-6'

The difference looks to be the handling of a case clause that doesn't match and doesn't have an else block. Most db's including PG have the result of a case block with no matches and no else to be 'null'. It seems DF is '1'

> select CASE WHEN NULL BETWEEN - 88 AND ( - - 91 ) * - AVG ( 95 ) THEN COUNT ( - 34 ) END;
+------------------------------------------------------------------------------------------------------+
| CASE WHEN NULL BETWEEN Int64(-88) AND (- Int64(-91)) * (- avg(Int64(95))) THEN count(Int64(-34)) END |
+------------------------------------------------------------------------------------------------------+
| 1                                                                                                    |
+------------------------------------------------------------------------------------------------------+

The following is duckdb's behavior with the same sql:

D select CASE WHEN NULL BETWEEN - 88 AND ( - - 91 ) * - AVG ( 95 ) THEN COUNT ( - 34 ) END;
┌───────────────────────────────────────────────────────────────────────────────────────┐
│ CASE  WHEN ((NULL BETWEEN -88 AND (91 * -(avg(95))))) THEN (count(-34)) ELSE NULL END │
│                                         int64                                         │
├───────────────────────────────────────────────────────────────────────────────────────┤
│                                                                                       │
└───────────────────────────────────────────────────────────────────────────────────────┘
D select typeof(CASE WHEN NULL BETWEEN - 88 AND ( - - 91 ) * - AVG ( 95 ) THEN COUNT ( - 34 ) END);
┌───────────────────────────────────────────────────────────────────────────────────────────────┐
│ typeof(CASE  WHEN ((NULL BETWEEN -88 AND (91 * -(avg(95))))) THEN (count(-34)) ELSE NULL END) │
│                                            varchar                                            │
├───────────────────────────────────────────────────────────────────────────────────────────────┤
│ BIGINT                                                                                        │
└───────────────────────────────────────────────────────────────────────────────────────────────┘

To Reproduce

sql above.

Expected behavior

I would expect the same result as PG and other db's.

Additional context

No response

@Omega359 Omega359 added the bug Something isn't working label Dec 14, 2024
@Omega359
Copy link
Contributor Author

I believe another sql that has the same cause is:

External error: query result mismatch:
[SQL] SELECT ALL + CASE WHEN AVG ( ALL + 88 ) >= 74 + + - 95 - CASE 23 WHEN 41 + - COUNT ( 16 ) THEN + 48 - 12 * + 70 - - ( - 95 ) * + 50 + 37 + + + COALESCE ( - 68, - - ( ( + 66 ) ) / + 28 ) END - + - 38 THEN + AVG ( 19 ) END - + 69
[Diff] (-expected|+actual)
-   NULL
+   -50
at test_files/sqlite/random/expr/slt_good_104.slt:38923

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