[PGSQL] Linq2db inserts incorrect value into postgre date column
See original GitHub issuelinq2db 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:
- Created 3 years ago
- Comments:12 (5 by maintainers)
Top 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 >
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
Actually it is better to cache, for memory and performance reasons.
Can we close an issue?
Prepare MappingSchema and pass it to DataConnection constructor or call AddMappingSchema