.executeTakeFirstOrThrow() returns null instead of throwing
See original GitHub issueDescription
When executing a SELECT
query with .executeTakeFirstOrThrow()
, it returns null
if the result set is empty instead of throwing an exception.
Environment
Name | Version |
---|---|
macOS | 13.0 |
Node | 16.17.0 |
npm | 8.15.0 |
Kysely | 0.22.0 |
Kysely Codegen | 0.7.4 |
MySQL | 5.7.38 |
mysql2 | 2.3.3 |
Additional Details
- Query was verified to return
[]
with.execute()
- Query was verified to return
undefined
with.executeTakeFirst()
- Query was verified to throw a
NoResultError
exception when the connection details were invalid - Return type from
.executeTakeFirstOrThrow()
does not reflect the potential fornull
- Issue occurs when using
min
andmax
aggregate functions; potentially others - Query verified to throw a
NoResultError
when selecting columns without using aggregate functions
Issue Analytics
- State:
- Created a year ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
SelectQueryBuilder | kysely
Executes the query and returns the first result or throws if the query returned no result. By default an instance of NoResultError is...
Read more >PostgreSQL 11 returns null instead of exception if previous ...
Try to EXPLAIN that query throwing exception, it should just output query plan, but instead it will throw exception - because it decided...
Read more >sqlite3 can only bind numbers, strings, bigints, buffers, and null ...
In my case I'm testing with both objects and arrays. This is in spite the examples in the docs include array and object...
Read more >Why does my SELECT query not return null values? [duplicate]
This happens because col IN (1,null) returns TRUE if col=1 , and NULL otherwise (i.e. it can never return FALSE ). Since NOT...
Read more >sql query should return 0 instead of NULL - CodeProject
SQL. SELECT ISNULL(SUM(Pairs), 0) AS previous_pairs FROM payout WHERE user_id = '100001'.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yep, that query always returns one row, even if the set from which
max
is taken is empty. That’s how SQL works. As mentioned, we can improve by making the aggregated values nullable, but it won’t change this behavior.avg
,max
,min
&sum
are nullable when they don’t have rows to work with.In a future release you’ll be able to opt-in to hinting they are nullable, and/or wrap them with
coalesce
.