SQLHydra's maxBy causes SqlHydra code to fail if querying an empty table
See original GitHub issueNoticed this when trying to use a maxBy on an empty table. We were able to work around with a sortByDescending into take 1, (we also could grab a count and branch on whether that returned anything) but wanted to suggest it might be a bit more intuitive to have maxBy handle the null without breaking; perhaps by returning an option?
This problem was encountered using SqlHydra.SqlServer.
I believe this should be reproducible by creating a database with an empty table, creating the schema for said table, and querying for a maxBy on one of the fields. Our particular field was a dateTime2(6)
if that is relevant.
Issue Analytics
- State:
- Created 6 months ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Issues · JordanMarr/SqlHydra
SqlHydra is a suite of NuGet packages for working with databases in F# ... SQLHydra's maxBy causes SqlHydra code to fail if querying...
Read more >sql server - Application querying empty tables
Yes many empty tables and queries to empty tables are indication of sloppy coding. But if you are having major performance issues this...
Read more >sql server 2005 - How to return a failure if a table is empty
I need to add a step to check if a table is empty, and somehow fail the step if it is. It's easy...
Read more >Copy Activity fails due to empty data returned from Source ...
Copy Activity fails due to empty data returned from Source data store - Microsoft Q&A.
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 Free
Top 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
Very creative fix! I think that would definitely be helpful to have in the readme! Also, table names are now generated. See notes for this release.
Hey @mjdupontMEA (and anyone else stumbling across this), I discovered a workaround without needing modifications. From your earlier example:
if you change it to
it’ll work properly because by selecting the max of
Some record.entry_timestamp
, it makes SqlHydra treat the type as an Option, and it successfully parses DBNull instead of crashing. I wonder if this is worth including in the docs by aggregates? It seems like a fairly common use case where you select an aggregate that might return NULL…