question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[PGSQL] Linq2db inserts incorrect value into postgre date column

See original GitHub issue

linq2db 3.1.5, PG SQL 12.2.

Linq2db inserts incorrect value into postgre date column. As example, value 2020-10-21 inserted as 2020-10-20.

Steps to reproduce

create script:

CREATE TABLE test."Samples"
(
    "Id" uuid NOT NULL,
    "Day" date NOT NULL,
    "UpdatedOn" timestamp with time zone NOT NULL,
    CONSTRAINT "PK_Samples" PRIMARY KEY ("Id")
)

table definition:

	[Table(Schema="test", Name="Samples")]
	public partial class Sample
	{
		[PrimaryKey, NotNull] public Guid           Id              { get; set; } // uuid

		[Column,     NotNull] public DateTimeOffset Day             { get; set; } // date

		[Column,     NotNull] public DateTimeOffset UpdatedOn       { get; set; } // timestamp (6) with time zone
	}

test code:

		[Test]
		public async Task DateTimeOffsetTests_Ok()
		{
			await using var db = _dbFactory();

			var now = DateTimeOffset.Now;
			var today = now.TruncateTime();
			var sample = new Sample
			{
				Id = Guid.NewGuid(),
				Day = today,
				UpdatedOn = now
			};

			await db.InsertAsync(sample);

			var sample2 = await db.Samples.FirstAsync(x => x.Id == sample.Id);

			sample2.Day.Should().Be(today);
			sample2.UpdatedOn.Should().BeCloseTo(now, TimeSpan.FromMilliseconds(1));
		}

test output:

Expected sample2.Day to be <2020-10-21 +3h>, but it was <2020-10-20 +3h>.

expected behavior: the test should pass:)

Environment details

linq2db version: 3.1.5 Database Server: PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) Database Provider: PostgreSQLVersion.v95 Operating system: Debian 12.2-2 .NET Framework: 3.1.402

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sdanylivcommented, Oct 23, 2020

Actually it is better to cache, for memory and performance reasons.

Can we close an issue?

1reaction
sdanylivcommented, Oct 22, 2020

Prepare MappingSchema and pass it to DataConnection constructor or call AddMappingSchema

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot write DateTime with Kind=UTC to PostgreSQL type ...
A. Solved by adding. AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); to the Startup Configure method.
Read more >
Insert Data into a Table in PostgreSQL
To insert a date value to the column with DATE datatype, need to specify the date in 'YYYY-MM-DD' format. If the table has...
Read more >
Understanding PostgreSQL Date Types and Functions ...
The default value in a DATE column in a Postgres database can be set by using the keyword DEFAULT CURRENT DATE , as...
Read more >
Documentation: 15: INSERT
INSERT inserts new rows into a table. One can insert one or more rows specified by value expressions, or zero or more rows...
Read more >
Bulk Copy (Bulk Insert)
Some options explained below. KeepIdentity option (default : false ). This option allows you to insert provided values into the identity column. It...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found