From 010e174de7b058ec23a28cc2ccbda36d86834503 Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Thu, 15 Jun 2023 13:55:15 +0200 Subject: [PATCH] Change CURRENT_TIMESTAMP parameter for col_default_is MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It turns out i have been **years** doing this wrong: you are supposed to pass that value as a text, like 'CURRENT_TIMESTAMP', not like the keyword so that it returns the current timestamp as a timestamptz. However, i have been doing it wrong because of a bug in previous versions of pgTAP[0], that did not take into account keywords such as CURRENT_TIMESTAMP or CURRENT_DATE and was comparing their actual values, not the names, therefore i thought that i misread the documentation. Only now have discovered this because DebianĀ 12 upgraded pgTAP version to 1.2.0. [0]: https://github.com/theory/pgtap/issues/244 --- test/company.sql | 2 +- test/contact.sql | 2 +- test/expense.sql | 2 +- test/invoice.sql | 4 ++-- test/login_attempt.sql | 2 +- test/product.sql | 2 +- test/quote.sql | 4 ++-- test/user.sql | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/company.sql b/test/company.sql index 7cd44f3..24d992e 100644 --- a/test/company.sql +++ b/test/company.sql @@ -123,7 +123,7 @@ select has_column('company', 'created_at'); select col_type_is('company', 'created_at', 'timestamp with time zone'); select col_not_null('company', 'created_at'); select col_has_default('company', 'created_at'); -select col_default_is('company', 'created_at', current_timestamp); +select col_default_is('company', 'created_at', 'CURRENT_TIMESTAMP'); set client_min_messages to warning; diff --git a/test/contact.sql b/test/contact.sql index a47fe99..d8cada8 100644 --- a/test/contact.sql +++ b/test/contact.sql @@ -110,7 +110,7 @@ select has_column('contact', 'created_at'); select col_type_is('contact', 'created_at', 'timestamp with time zone'); select col_not_null('contact', 'created_at'); select col_has_default('contact', 'created_at'); -select col_default_is('contact', 'created_at', current_timestamp); +select col_default_is('contact', 'created_at', 'CURRENT_TIMESTAMP'); set client_min_messages to warning; truncate contact cascade; diff --git a/test/expense.sql b/test/expense.sql index 2217673..e5434f1 100644 --- a/test/expense.sql +++ b/test/expense.sql @@ -82,7 +82,7 @@ select has_column('expense', 'created_at'); select col_type_is('expense', 'created_at', 'timestamp with time zone'); select col_not_null('expense', 'created_at'); select col_has_default('expense', 'created_at'); -select col_default_is('expense', 'created_at', current_timestamp); +select col_default_is('expense', 'created_at', 'CURRENT_TIMESTAMP'); set client_min_messages to warning; diff --git a/test/invoice.sql b/test/invoice.sql index 377d54a..5471884 100644 --- a/test/invoice.sql +++ b/test/invoice.sql @@ -52,7 +52,7 @@ select has_column('invoice', 'invoice_date'); select col_type_is('invoice', 'invoice_date', 'date'); select col_not_null('invoice', 'invoice_date'); select col_has_default('invoice', 'invoice_date'); -select col_default_is('invoice', 'invoice_date', current_date); +select col_default_is('invoice', 'invoice_date', 'CURRENT_DATE'); select has_column('invoice', 'contact_id'); select col_is_fk('invoice', 'contact_id'); @@ -99,7 +99,7 @@ select has_column('invoice', 'created_at'); select col_type_is('invoice', 'created_at', 'timestamp with time zone'); select col_not_null('invoice', 'created_at'); select col_has_default('invoice', 'created_at'); -select col_default_is('invoice', 'created_at', current_timestamp); +select col_default_is('invoice', 'created_at', 'CURRENT_TIMESTAMP'); set client_min_messages to warning; diff --git a/test/login_attempt.sql b/test/login_attempt.sql index b71c299..2837abc 100644 --- a/test/login_attempt.sql +++ b/test/login_attempt.sql @@ -42,7 +42,7 @@ select has_column('login_attempt', 'attempted_at'); select col_type_is('login_attempt', 'attempted_at', 'timestamp with time zone'); select col_not_null('login_attempt', 'attempted_at'); select col_has_default('login_attempt', 'attempted_at'); -select col_default_is('login_attempt', 'attempted_at', current_timestamp); +select col_default_is('login_attempt', 'attempted_at', 'CURRENT_TIMESTAMP'); select * from finish(); diff --git a/test/product.sql b/test/product.sql index 4651992..8b99d4c 100644 --- a/test/product.sql +++ b/test/product.sql @@ -68,7 +68,7 @@ select has_column('product', 'created_at'); select col_type_is('product', 'created_at', 'timestamp with time zone'); select col_not_null('product', 'created_at'); select col_has_default('product', 'created_at'); -select col_default_is('product', 'created_at', current_timestamp); +select col_default_is('product', 'created_at', 'CURRENT_TIMESTAMP'); set client_min_messages to warning; diff --git a/test/quote.sql b/test/quote.sql index 299b938..8f00def 100644 --- a/test/quote.sql +++ b/test/quote.sql @@ -52,7 +52,7 @@ select has_column('quote', 'quote_date'); select col_type_is('quote', 'quote_date', 'date'); select col_not_null('quote', 'quote_date'); select col_has_default('quote', 'quote_date'); -select col_default_is('quote', 'quote_date', current_date); +select col_default_is('quote', 'quote_date', 'CURRENT_DATE'); select has_column('quote', 'quote_status'); select col_is_fk('quote', 'quote_status'); @@ -91,7 +91,7 @@ select has_column('quote', 'created_at'); select col_type_is('quote', 'created_at', 'timestamp with time zone'); select col_not_null('quote', 'created_at'); select col_has_default('quote', 'created_at'); -select col_default_is('quote', 'created_at', current_timestamp); +select col_default_is('quote', 'created_at', 'CURRENT_TIMESTAMP'); set client_min_messages to warning; diff --git a/test/user.sql b/test/user.sql index b98d906..d9c8186 100644 --- a/test/user.sql +++ b/test/user.sql @@ -68,7 +68,7 @@ select has_column('user', 'created_at'); select col_type_is('user', 'created_at', 'timestamp with time zone'); select col_not_null('user', 'created_at'); select col_has_default('user', 'created_at'); -select col_default_is('user', 'created_at', current_timestamp); +select col_default_is('user', 'created_at', 'CURRENT_TIMESTAMP'); select *