Skip to content

Support for built-in PostgreSQL ranges #63

Closed

Description

@roji

Users can create arbitrary range types, but Npgsql's EF Core type mapper currently doesn't look at the database to construct the mappings (singleton), making it impossible to know the datatype name for a given NpgsqlRange. What we can do is support the built-in range types, which will probably be enough.

Includes scaffolding support.

Activity

  1. modified the milestone: 1.1.0 on Jul 10, 2016
  2. modified the milestones: 1.1.0, on Nov 3, 2016
  3. changed the title [-]Scaffold range types[/-] [+]Support for built-in PostgreSQL ranges[/+] on Dec 15, 2016
  4. roji commented on Dec 18, 2016

    @roji
    MemberAuthor

    Scaffolding depends on dotnet/efcore#7269

  5. wub commented on May 1, 2017

    @wub

    dotnet/efcore#7269 is done now - is there anything else blocking this?

    Thanks for all the hard work, @roji. If it weren't for npgsql I probably wouldn't be using .NET Core!

  6. roji commented on May 5, 2017

    @roji
    MemberAuthor

    dotnet/efcore#7269 was only blocking for scaffolding support, which isn't very critical. If I remember correctly I already added support for built-in range types (e.g. int4range, daterange...) to the current dev branch, so if you're feeling brave you can try to compile the provider yourself and use ranges (would love to hear about it).

    Non-built-in ranges (which you can create with CREATE TYPE) aren't supported yet and would require a more significant refactor in how type mapping works.

  7. modified the milestones: 2.0.0, 2.1.0 on Jul 22, 2017
  8. 1 remaining item

  9. removed this from the 2.0.0 milestone on Jul 22, 2017
  10. SirGordon commented on Aug 25, 2017

    @SirGordon

    Is it shipped with 2.0? Trying to add migration with a field
    [Column("length")] public NpgsqlRange<int> Length { get; set; }
    But I get

    Error: The property 'RoadAlgorithmData.Length' is of type 'NpgsqlRange' which is not supported by current database provider.

  11. dpsenner commented on Feb 15, 2018

    @dpsenner

    bump The issue is still open but has milestone 2.0.0. Will it be shipped with the next release or is it going to be delayed?

  12. roji commented on Feb 17, 2018

    @roji
    MemberAuthor

    I didn't manage to release this for 2.0.0, but I do hope to do this for the upcoming 2.1.0 release (for built-in types only at this stage). Anyone who's interested should upvote to let me know you need it, in case I don't have time to do everything on the plan.

  13. dpsenner commented on Feb 21, 2018

    @dpsenner

    That's great news to hear! Looking forward to see 2.1.0 happen!

  14. roji commented on Feb 22, 2018

    @roji
    MemberAuthor

    This is done and will be probably be released with 2.1.0-preview1.

    Note that this only includes the 6 built-in range types, and not range types created by the user. It also doesn't map any operations yet - it only allows you to have NpgsqlRange<T> on your entities and have that correctly mapped to the database. For mapping range operations I've opened #311 - it shouldn't be too hard and may even make it for 2.1.

  15. added 2 commits that reference this issue on Feb 22, 2018
    af84c69
    8bff27e
  16. roji commented on Mar 8, 2018

    @roji
    MemberAuthor

    @austindrenski, PostgreSQL actually supports defining your own range types, and it's very easy to define on over floating-point types (see the example in the PostgreSQL docs).

    The only problem is that currently the EF Core provider only supports the built-in types, which don't including the floating-point types (see #329 for adding user-defined ranges and why it's not trivial). In the meantime, I don't think it makes sense to automatically map CLR float/double to PostgreSQL numeric, since these are quite different types, and since one day we may actually support user-defined ranges at which point things will probably break. The conversion between range and range would have to be supported at the Npgsql level, which I really don't want to do.

    Besides, with the new value converters coming in 2.1 it should be pretty trivial to write a conversion between the two types...

  17. austindrenski commented on Mar 8, 2018

    @austindrenski
    Contributor

    That makes sense. Thanks for providing some context, much appreciated!

  18. dpsenner commented on Aug 2, 2018

    @dpsenner

    @roji It appears to me that the mapping of DateTimeOffset was forgotten in the implementation, am I right?

    I ask because we chose to explicitly map any timestamp to DateTimeOffset in an attempt to avoid timestamp skews caused by typos of DateTime.Now where it should read as DateTime.UtcNow because DateTimeOffset.Now behaves like DateTimeOffset.UtcNow. DateTimeOffset also provides better synergies for integration with grpc / protobuf. With the implementation given we are forced to use DateTime over DateTimeOffset and thus mix concepts in the application code.

  19. roji commented on Aug 2, 2018

    @roji
    MemberAuthor

    @dpsenner first, regarding your decision to use DateTimeOffset in order to avoid timezone issues, I'm not a big fan :) See the following long rants if you're interested: #303, #473.

    Regarding support of ranges over timestamptz, the discussion took place in #561.

  20. dpsenner commented on Aug 6, 2018

    @dpsenner

    Future readers, please ignore my comment above. If you are reading this you should consider to use timestamp over timestamptz along with NodaTime Instants in your model. This makes your application layer responsible for dealing with timezoned information and that's the best place to have that logic. Note that reporting tools deliberately choose to discard any interpretations of timestamptz columns, effectively making them utc timestamps. People should think about how to store and interpret application data that comes from and goes to multiple timezones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions