From 9a1018a3287e56aa297565ed13848467418b4714 Mon Sep 17 00:00:00 2001 From: Ivan Krivosheev Date: Wed, 30 Mar 2022 20:30:22 +0300 Subject: [PATCH] issues-285 Fix timestamp_with_time_zone_len --- src/backend/postgres/table.rs | 2 +- src/tests_cfg.rs | 2 ++ tests/postgres/table.rs | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/backend/postgres/table.rs b/src/backend/postgres/table.rs index adef7cc2c6..a8116f88cb 100644 --- a/src/backend/postgres/table.rs +++ b/src/backend/postgres/table.rs @@ -68,7 +68,7 @@ impl TableBuilder for PostgresQueryBuilder { None => "timestamp".into(), }, ColumnType::TimestampWithTimeZone(precision) => match precision { - Some(precision) => format!("timestamp with time zone({})", precision), + Some(precision) => format!("timestamp({}) with time zone", precision), None => "timestamp with time zone".into(), }, ColumnType::Time(precision) => match precision { diff --git a/src/tests_cfg.rs b/src/tests_cfg.rs index 678ee983e9..a8cf965ee8 100644 --- a/src/tests_cfg.rs +++ b/src/tests_cfg.rs @@ -21,6 +21,7 @@ pub enum Character { SizeW, SizeH, FontId, + CreatedAt, } /// A shorthand for [`Character`] @@ -39,6 +40,7 @@ impl Iden for Character { Self::SizeW => "size_w", Self::SizeH => "size_h", Self::FontId => "font_id", + Self::CreatedAt => "created_at", } ) .unwrap(); diff --git a/tests/postgres/table.rs b/tests/postgres/table.rs index e644ea2858..0a447781fd 100644 --- a/tests/postgres/table.rs +++ b/tests/postgres/table.rs @@ -232,6 +232,26 @@ fn create_10() { ); } +#[test] +fn create_11() { + assert_eq!( + Table::create() + .table(Char::Table) + .col( + ColumnDef::new(Char::CreatedAt) + .timestamp_with_time_zone_len(0) + .not_null() + ) + .to_string(PostgresQueryBuilder), + vec![ + r#"CREATE TABLE "character" ("#, + r#""created_at" timestamp(0) with time zone NOT NULL"#, + r#")"#, + ] + .join(" ") + ); +} + #[test] fn drop_1() { assert_eq!(