From f77a7d822bc1f976e8c754e5b570f71ba7b99572 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Fri, 27 May 2022 16:12:11 +0800 Subject: [PATCH] PostgreSQL datetime and timestamp datatype are equivalent --- src/postgres/writer/column.rs | 6 ++++-- tests/live/postgres/src/main.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/postgres/writer/column.rs b/src/postgres/writer/column.rs index f4215da2..edad4c63 100644 --- a/src/postgres/writer/column.rs +++ b/src/postgres/writer/column.rs @@ -103,9 +103,11 @@ impl ColumnInfo { col_def.binary(); } Type::Timestamp(time_attr) => { + // The SQL standard requires that writing just timestamp be equivalent to timestamp without time zone, + // and PostgreSQL honors that behavior. (https://www.postgresql.org/docs/current/datatype-datetime.html) match time_attr.precision { - Some(precision) => col_def.timestamp_len(precision.into()), - None => col_def.timestamp(), + Some(precision) => col_def.date_time_len(precision.into()), + None => col_def.date_time(), }; } Type::TimestampWithTimeZone(time_attr) => { diff --git a/tests/live/postgres/src/main.rs b/tests/live/postgres/src/main.rs index e5dd0e04..8b8665e1 100644 --- a/tests/live/postgres/src/main.rs +++ b/tests/live/postgres/src/main.rs @@ -207,7 +207,7 @@ fn create_order_table() -> TableCreateStatement { ) .col( ColumnDef::new(Alias::new("placed_at")) - .timestamp_len(6) + .date_time_len(6) .not_null(), ) .primary_key(