Skip to content

Commit

Permalink
PostgreSQL datetime and timestamp datatype are equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed May 27, 2022
1 parent 00429f3 commit f77a7d8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/postgres/writer/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/live/postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f77a7d8

Please sign in to comment.