Comments (7)
Probably provide a mechanism for opting out of this.
Think hard about what this means for existing databases.
from efcore.pg.
The main trigger for this feature was the EF Core functional test suite, which was written and tested on SQL Server where nulls are sorted first, so many tests would fail and had to be skipped.
As this feature probably isn't interesting in any other context, implemented a context option for generating ORDER BY ... NULLS FIRST
, but without any index generation - at the moment this is solely for running the EF Core tests properly. The methods involved are internal to avoid users invoking them and triggering a performance degradation (because indexes are still nulls last).
If anyone is interested in having this exposed publicly please post here.
from efcore.pg.
@roji I would be interested in using this feature if it were exposed publicly.
from efcore.pg.
@richardsheppard-avalara would it be possible to know more about your use case, and why you think you need this?
from efcore.pg.
@roji I might have misread the purpose this ticket, but the use case is we have certain numeric fields in our database that are nullable which cause issues when sorting. We have APIs wrapped around our tables, so that user can specify which properties they would like to sort on and the direction (asc or desc), but when they try to sort a numeric field using desc the null values sort to the top, they would rather see them sort last. I believe that would be the nulls last option.
from efcore.pg.
@richardsheppard-avalara thanks for the details - it does sound like this feature could be what you want. If I understood correctly you want nulls to always sort at the end, but when specifying a descending sort they're sorted at the beginning. This makes me see that I've implemented NULLS FIRST
, but there's no option for specifying NULLS LAST
(which would sort last regardless of ascending/descending).
FWIW, in C# OrderBy()
places nulls at the beginning, but when you use OrderByDescending()
they get sorted to the end. In other words, in C# you have no option for specifying null sorting - nulls are always considered "smaller" than non-nulls (whereas PostgreSQL considers them "greater" than non-nulls by default).
Simply tacking on NULLS FIRST
or NULLS LAST
is easy enough, but this needs to happen on indices as well (https://www.postgresql.org/docs/current/static/indexes-ordering.html), and anyone changing the null sorting behavior in a migration needs to be duly warned etc.
I definitely won't be able to implement this anytime soon. Anyone else who's interested in this should post or vote to let me know they need it.
from efcore.pg.
FYI pushed aa2d342 which places NULLS LAST
on descending sorts (previously we were placing NULLS FIRST
on all sorts). This makes PostgreSQL behave just like C# OrderBy/OrderByDescending.
from efcore.pg.
Related Issues (20)
- Writing values of 'NpgsqlTypes.NpgsqlRange`1[[System.TimeSpan, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]][]' is not supported for parameters having NpgsqlDbType '-2147483608'. HOT 3
- Error : ''failure to parse near offset 7489. expected an ascii digit,, when runing from EF core .Net 8 HOT 2
- Error : ''failure to parse near offset 7489. expected an ascii digit,, when runing from EF core .Net 8 HOT 5
- Feature Request: protect connection string literal in memory HOT 2
- Support value conversion with generated properties HOT 4
- Running simultaneous queries on different DbContext instances leads to `NpgsqlOperationInProgressException` HOT 3
- Map User Defined Function return table value with parameter timestamp without time zone HOT 3
- Cannot rename system column "xmin" HOT 3
- Reverse engineering for view does not preserve nullability of columns HOT 4
- ISSUE: A PostgreSQL type with the oid '0' was not found in the current database info HOT 1
- SQL translation error when using LEFT JOIN in `Where` HOT 6
- Upgrading INpgsqlArrayConverter to PrimitiveCollection
- EF.Functions support for json_array_length HOT 2
- Npgsql.PostgresException (0x80004005): 42883: function st_contains(deployment.geometry, deployment.geometry) does not exist HOT 4
- ISet<EnumType>.Contains() does not translate in EF Core 8 HOT 1
- EF.Functions.JsonContains() occurs issue after upgrade to .net 8
- Querying a DateTimeOffset in a jsonb as JsonDocument fails with InvalidCastException
- Translation from Contains to strpos leads to extremely slow queries HOT 1
- GroupBy with joined table produces sub optimal query
- Unable to write data to the transport connection: Operation canceled. HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from efcore.pg.