]> granicus.if.org Git - postgresql/commitdiff
Extend 'guc' regression test to check manipulations of datestyle as
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 13 Aug 2006 19:31:06 +0000 (19:31 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 13 Aug 2006 19:31:06 +0000 (19:31 +0000)
well as vacuum_cost_delay.  Since datestyle is a string variable,
this exercises memory allocation issues that might not appear when
modifying an integer GUC variable.  Also, we can observe the side
effects of changing datestyle to check that assign hooks are called
at the right times.

src/test/regress/expected/guc.out
src/test/regress/sql/guc.sql

index fb6d0d774df9f4b95a999ff69be08896cb58eda1..ca1b582630d58a536c8ce88ab9801bd94a5d5e32 100644 (file)
@@ -1,11 +1,32 @@
--- SET vacuum_cost_delay to some value
+-- pg_regress should ensure that this default value applies; however
+-- we can't rely on any specific default value of vacuum_cost_delay
+SHOW datestyle;
+   DateStyle   
+---------------
+ Postgres, MDY
+(1 row)
+
+-- SET to some nondefault value
 SET vacuum_cost_delay TO 400;
+SET datestyle = 'ISO, YMD';
 SHOW vacuum_cost_delay;
  vacuum_cost_delay 
 -------------------
  400ms
 (1 row)
 
+SHOW datestyle;
+ DateStyle 
+-----------
+ ISO, YMD
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+      timestamptz       
+------------------------
+ 2006-08-13 12:34:56-07
+(1 row)
+
 -- SET LOCAL has no effect outside of a transaction
 SET LOCAL vacuum_cost_delay TO 500;
 SHOW vacuum_cost_delay;
@@ -14,6 +35,19 @@ SHOW vacuum_cost_delay;
  400ms
 (1 row)
 
+SET LOCAL datestyle = 'SQL';
+SHOW datestyle;
+ DateStyle 
+-----------
+ ISO, YMD
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+      timestamptz       
+------------------------
+ 2006-08-13 12:34:56-07
+(1 row)
+
 -- SET LOCAL within a transaction that commits
 BEGIN;
 SET LOCAL vacuum_cost_delay TO 500;
@@ -23,6 +57,19 @@ SHOW vacuum_cost_delay;
  500ms
 (1 row)
 
+SET LOCAL datestyle = 'SQL';
+SHOW datestyle;
+ DateStyle 
+-----------
+ SQL, YMD
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+       timestamptz       
+-------------------------
+ 08/13/2006 12:34:56 PDT
+(1 row)
+
 COMMIT;
 SHOW vacuum_cost_delay;
  vacuum_cost_delay 
@@ -30,6 +77,18 @@ SHOW vacuum_cost_delay;
  400ms
 (1 row)
 
+SHOW datestyle;
+ DateStyle 
+-----------
+ ISO, YMD
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+      timestamptz       
+------------------------
+ 2006-08-13 12:34:56-07
+(1 row)
+
 -- SET should be reverted after ROLLBACK
 BEGIN;
 SET vacuum_cost_delay TO 600;
@@ -39,6 +98,19 @@ SHOW vacuum_cost_delay;
  600ms
 (1 row)
 
+SET datestyle = 'German';
+SHOW datestyle;
+  DateStyle  
+-------------
+ German, DMY
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+       timestamptz       
+-------------------------
+ 13.08.2006 12:34:56 PDT
+(1 row)
+
 ROLLBACK;
 SHOW vacuum_cost_delay;
  vacuum_cost_delay 
@@ -46,20 +118,83 @@ SHOW vacuum_cost_delay;
  400ms
 (1 row)
 
+SHOW datestyle;
+ DateStyle 
+-----------
+ ISO, YMD
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+      timestamptz       
+------------------------
+ 2006-08-13 12:34:56-07
+(1 row)
+
 -- Some tests with subtransactions
 BEGIN;
 SET vacuum_cost_delay TO 700;
+SET datestyle = 'MDY';
+SHOW datestyle;
+ DateStyle 
+-----------
+ ISO, MDY
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+      timestamptz       
+------------------------
+ 2006-08-13 12:34:56-07
+(1 row)
+
 SAVEPOINT first_sp;
 SET vacuum_cost_delay TO 800;
-ROLLBACK TO first_sp;
 SHOW vacuum_cost_delay;
  vacuum_cost_delay 
 -------------------
- 700ms
+ 800ms
+(1 row)
+
+SET datestyle = 'German, DMY';
+SHOW datestyle;
+  DateStyle  
+-------------
+ German, DMY
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+       timestamptz       
+-------------------------
+ 13.08.2006 12:34:56 PDT
+(1 row)
+
+ROLLBACK TO first_sp;
+SHOW datestyle;
+ DateStyle 
+-----------
+ ISO, MDY
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+      timestamptz       
+------------------------
+ 2006-08-13 12:34:56-07
 (1 row)
 
 SAVEPOINT second_sp;
 SET vacuum_cost_delay TO 900;
+SET datestyle = 'SQL, YMD';
+SHOW datestyle;
+ DateStyle 
+-----------
+ SQL, YMD
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+       timestamptz       
+-------------------------
+ 08/13/2006 12:34:56 PDT
+(1 row)
+
 SAVEPOINT third_sp;
 SET vacuum_cost_delay TO 1000;
 SHOW vacuum_cost_delay;
@@ -68,6 +203,19 @@ SHOW vacuum_cost_delay;
  1s
 (1 row)
 
+SET datestyle = 'Postgres, MDY';
+SHOW datestyle;
+   DateStyle   
+---------------
+ Postgres, MDY
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+         timestamptz          
+------------------------------
+ Sun Aug 13 12:34:56 2006 PDT
+(1 row)
+
 ROLLBACK TO third_sp;
 SHOW vacuum_cost_delay;
  vacuum_cost_delay 
@@ -75,6 +223,18 @@ SHOW vacuum_cost_delay;
  900ms
 (1 row)
 
+SHOW datestyle;
+ DateStyle 
+-----------
+ SQL, YMD
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+       timestamptz       
+-------------------------
+ 08/13/2006 12:34:56 PDT
+(1 row)
+
 ROLLBACK TO second_sp;
 SHOW vacuum_cost_delay;
  vacuum_cost_delay 
@@ -82,7 +242,37 @@ SHOW vacuum_cost_delay;
  700ms
 (1 row)
 
+SHOW datestyle;
+ DateStyle 
+-----------
+ ISO, MDY
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+      timestamptz       
+------------------------
+ 2006-08-13 12:34:56-07
+(1 row)
+
 ROLLBACK;
+SHOW vacuum_cost_delay;
+ vacuum_cost_delay 
+-------------------
+ 400ms
+(1 row)
+
+SHOW datestyle;
+ DateStyle 
+-----------
+ ISO, YMD
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+      timestamptz       
+------------------------
+ 2006-08-13 12:34:56-07
+(1 row)
+
 -- SET LOCAL with Savepoints
 BEGIN;
 SHOW vacuum_cost_delay;
@@ -91,6 +281,18 @@ SHOW vacuum_cost_delay;
  400ms
 (1 row)
 
+SHOW datestyle;
+ DateStyle 
+-----------
+ ISO, YMD
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+      timestamptz       
+------------------------
+ 2006-08-13 12:34:56-07
+(1 row)
+
 SAVEPOINT sp;
 SET LOCAL vacuum_cost_delay TO 300;
 SHOW vacuum_cost_delay;
@@ -99,6 +301,19 @@ SHOW vacuum_cost_delay;
  300ms
 (1 row)
 
+SET LOCAL datestyle = 'Postgres, MDY';
+SHOW datestyle;
+   DateStyle   
+---------------
+ Postgres, MDY
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+         timestamptz          
+------------------------------
+ Sun Aug 13 12:34:56 2006 PDT
+(1 row)
+
 ROLLBACK TO sp;
 SHOW vacuum_cost_delay;
  vacuum_cost_delay 
@@ -106,7 +321,37 @@ SHOW vacuum_cost_delay;
  400ms
 (1 row)
 
+SHOW datestyle;
+ DateStyle 
+-----------
+ ISO, YMD
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+      timestamptz       
+------------------------
+ 2006-08-13 12:34:56-07
+(1 row)
+
 ROLLBACK;
+SHOW vacuum_cost_delay;
+ vacuum_cost_delay 
+-------------------
+ 400ms
+(1 row)
+
+SHOW datestyle;
+ DateStyle 
+-----------
+ ISO, YMD
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+      timestamptz       
+------------------------
+ 2006-08-13 12:34:56-07
+(1 row)
+
 -- SET followed by SET LOCAL
 BEGIN;
 SET vacuum_cost_delay TO 400;
@@ -117,6 +362,20 @@ SHOW vacuum_cost_delay;
  500ms
 (1 row)
 
+SET datestyle = 'ISO, DMY';
+SET LOCAL datestyle = 'Postgres, MDY';
+SHOW datestyle;
+   DateStyle   
+---------------
+ Postgres, MDY
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+         timestamptz          
+------------------------------
+ Sun Aug 13 12:34:56 2006 PDT
+(1 row)
+
 COMMIT;
 SHOW vacuum_cost_delay;
  vacuum_cost_delay 
@@ -124,16 +383,22 @@ SHOW vacuum_cost_delay;
  400ms
 (1 row)
 
+SHOW datestyle;
+ DateStyle 
+-----------
+ ISO, DMY
+(1 row)
+
+SELECT '2006-08-13 12:34:56'::timestamptz;
+      timestamptz       
+------------------------
+ 2006-08-13 12:34:56-07
+(1 row)
+
 --
 -- Test RESET.  We use datestyle because the reset value is forced by
 -- pg_regress, so it doesn't depend on the installation's configuration.
 --
-SHOW datestyle;
-   DateStyle   
----------------
- Postgres, MDY
-(1 row)
-
 SET datestyle = iso, ymd;
 SHOW datestyle;
  DateStyle 
@@ -141,6 +406,12 @@ SHOW datestyle;
  ISO, YMD
 (1 row)
 
+SELECT '2006-08-13 12:34:56'::timestamptz;
+      timestamptz       
+------------------------
+ 2006-08-13 12:34:56-07
+(1 row)
+
 RESET datestyle;
 SHOW datestyle;
    DateStyle   
@@ -148,3 +419,9 @@ SHOW datestyle;
  Postgres, MDY
 (1 row)
 
+SELECT '2006-08-13 12:34:56'::timestamptz;
+         timestamptz          
+------------------------------
+ Sun Aug 13 12:34:56 2006 PDT
+(1 row)
+
index 420f3f4386b914d76dda0b28716327226d2499d9..6d17a182412676d49f4f9f4bb84fb41db9b3a037 100644 (file)
--- SET vacuum_cost_delay to some value
+-- pg_regress should ensure that this default value applies; however
+-- we can't rely on any specific default value of vacuum_cost_delay
+SHOW datestyle;
+
+-- SET to some nondefault value
 SET vacuum_cost_delay TO 400;
+SET datestyle = 'ISO, YMD';
 SHOW vacuum_cost_delay;
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 
 -- SET LOCAL has no effect outside of a transaction
 SET LOCAL vacuum_cost_delay TO 500;
 SHOW vacuum_cost_delay;
+SET LOCAL datestyle = 'SQL';
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 
 -- SET LOCAL within a transaction that commits
 BEGIN;
 SET LOCAL vacuum_cost_delay TO 500;
 SHOW vacuum_cost_delay;
+SET LOCAL datestyle = 'SQL';
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 COMMIT;
 SHOW vacuum_cost_delay;
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 
 -- SET should be reverted after ROLLBACK
 BEGIN;
 SET vacuum_cost_delay TO 600;
 SHOW vacuum_cost_delay;
+SET datestyle = 'German';
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 ROLLBACK;
 SHOW vacuum_cost_delay;
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 
 -- Some tests with subtransactions
 BEGIN;
 SET vacuum_cost_delay TO 700;
+SET datestyle = 'MDY';
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 SAVEPOINT first_sp;
 SET vacuum_cost_delay TO 800;
-ROLLBACK TO first_sp;
 SHOW vacuum_cost_delay;
+SET datestyle = 'German, DMY';
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
+ROLLBACK TO first_sp;
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 SAVEPOINT second_sp;
 SET vacuum_cost_delay TO 900;
+SET datestyle = 'SQL, YMD';
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 SAVEPOINT third_sp;
 SET vacuum_cost_delay TO 1000;
 SHOW vacuum_cost_delay;
+SET datestyle = 'Postgres, MDY';
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 ROLLBACK TO third_sp;
 SHOW vacuum_cost_delay;
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 ROLLBACK TO second_sp;
 SHOW vacuum_cost_delay;
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 ROLLBACK;
+SHOW vacuum_cost_delay;
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 
 -- SET LOCAL with Savepoints
 BEGIN;
 SHOW vacuum_cost_delay;
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 SAVEPOINT sp;
 SET LOCAL vacuum_cost_delay TO 300;
 SHOW vacuum_cost_delay;
+SET LOCAL datestyle = 'Postgres, MDY';
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 ROLLBACK TO sp;
 SHOW vacuum_cost_delay;
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 ROLLBACK;
+SHOW vacuum_cost_delay;
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 
 -- SET followed by SET LOCAL
 BEGIN;
 SET vacuum_cost_delay TO 400;
 SET LOCAL vacuum_cost_delay TO 500;
 SHOW vacuum_cost_delay;
+SET datestyle = 'ISO, DMY';
+SET LOCAL datestyle = 'Postgres, MDY';
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 COMMIT;
 SHOW vacuum_cost_delay;
+SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 
 --
 -- Test RESET.  We use datestyle because the reset value is forced by
 -- pg_regress, so it doesn't depend on the installation's configuration.
 --
-SHOW datestyle;
 SET datestyle = iso, ymd;
 SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;
 RESET datestyle;
 SHOW datestyle;
+SELECT '2006-08-13 12:34:56'::timestamptz;