From 070a3ad76b65c9eff572da5d358c563ccc7bb14f Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Mon, 15 Aug 2005 23:00:14 +0000
Subject: [PATCH] Rename pg_stat_file columns to be more consistent.  Split
 apart change and creation columns to behave for Unix or Win32.

---
 doc/src/sgml/func.sgml               | 11 +++++-----
 src/backend/catalog/system_views.sql |  9 ++++----
 src/backend/utils/adt/genfile.c      | 31 ++++++++++++++++++----------
 src/include/catalog/catversion.h     |  4 ++--
 4 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index d9495e8ee48..c5c81a028ff 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -1,5 +1,5 @@
 <!--
-$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.280 2005/08/13 19:02:32 tgl Exp $
+$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.281 2005/08/15 23:00:13 momjian Exp $
 PostgreSQL documentation
 -->
 
@@ -9414,12 +9414,13 @@ SELECT set_config('log_statement_stats', 'off', false);
    </indexterm>
    <para>
     <function>pg_stat_file()</> returns a record containing the file
-    length, last accessed timestamp, last modified timestamp, 
-    creation timestamp, and a boolean indicating if it is a directory.
-    Typical usages include:
+    size, last accessed timestamp, last modified timestamp, 
+    last file status change timestamp (Unix platforms only), 
+    file creation timestamp (Win32 only), and a boolean indicating 
+    if it is a directory.  Typical usages include:
 <programlisting>
 SELECT * FROM pg_stat_file('filename');
-SELECT (pg_stat_file('filename')).mtime;
+SELECT (pg_stat_file('filename')).modification;
 </programlisting>
    </para>
 
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 1f091d55d35..10826e21f7b 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1996-2005, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.20 2005/08/15 16:25:17 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.21 2005/08/15 23:00:13 momjian Exp $
  */
 
 CREATE VIEW pg_roles AS 
@@ -346,8 +346,9 @@ UPDATE pg_proc SET
                          'timestamptz',
                          'timestamptz',
                          'timestamptz',
+                         'timestamptz',
                          'bool'],
-  proargmodes = ARRAY['i'::"char", 'o', 'o', 'o', 'o', 'o'],
-  proargnames = ARRAY['filename'::text,
-                      'length', 'atime', 'mtime', 'ctime','isdir']
+  proargmodes = ARRAY['i'::"char", 'o', 'o', 'o', 'o', 'o', 'o'],
+  proargnames = ARRAY['filename'::text, 'size', 'access', 'modification',
+		      'change', 'creation', 'isdir']
 WHERE oid = 'pg_stat_file(text)'::regprocedure;
diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c
index d67ed4c791f..43a05659a26 100644
--- a/src/backend/utils/adt/genfile.c
+++ b/src/backend/utils/adt/genfile.c
@@ -9,7 +9,7 @@
  * Author: Andreas Pflug <pgadmin@pse-consulting.de>
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/utils/adt/genfile.c,v 1.4 2005/08/13 19:02:34 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/utils/adt/genfile.c,v 1.5 2005/08/15 23:00:14 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -154,8 +154,8 @@ pg_stat_file(PG_FUNCTION_ARGS)
 	text	   *filename_t = PG_GETARG_TEXT_P(0);
 	char		*filename;
 	struct stat fst;
-	Datum		values[5];
-	bool		isnull[5];
+	Datum		values[6];
+	bool		isnull[6];
 	HeapTuple	tuple;
 	TupleDesc	tupdesc;
 
@@ -175,26 +175,35 @@ pg_stat_file(PG_FUNCTION_ARGS)
 	 * This record type had better match the output parameters declared
 	 * for me in pg_proc.h (actually, in system_views.sql at the moment).
 	 */
-	tupdesc = CreateTemplateTupleDesc(5, false);
+	tupdesc = CreateTemplateTupleDesc(6, false);
 	TupleDescInitEntry(tupdesc, (AttrNumber) 1,
-					   "length", INT8OID, -1, 0);
+					   "size", INT8OID, -1, 0);
 	TupleDescInitEntry(tupdesc, (AttrNumber) 2,
-					   "atime", TIMESTAMPTZOID, -1, 0);
+					   "access", TIMESTAMPTZOID, -1, 0);
 	TupleDescInitEntry(tupdesc, (AttrNumber) 3,
-					   "mtime", TIMESTAMPTZOID, -1, 0);
+					   "modification", TIMESTAMPTZOID, -1, 0);
 	TupleDescInitEntry(tupdesc, (AttrNumber) 4,
-					   "ctime", TIMESTAMPTZOID, -1, 0);
+					   "change", TIMESTAMPTZOID, -1, 0);
 	TupleDescInitEntry(tupdesc, (AttrNumber) 5,
+					   "creation", TIMESTAMPTZOID, -1, 0);
+	TupleDescInitEntry(tupdesc, (AttrNumber) 6,
 					   "isdir", BOOLOID, -1, 0);
 	BlessTupleDesc(tupdesc);
 
+	memset(isnull, false, sizeof(isnull));
+
 	values[0] = Int64GetDatum((int64) fst.st_size);
 	values[1] = TimestampTzGetDatum(time_t_to_timestamptz(fst.st_atime));
 	values[2] = TimestampTzGetDatum(time_t_to_timestamptz(fst.st_mtime));
+	/* Unix has file status change time, while Win32 has creation time */
+#if !defined(WIN32) && !defined(__CYGWIN__)
 	values[3] = TimestampTzGetDatum(time_t_to_timestamptz(fst.st_ctime));
-	values[4] = BoolGetDatum(fst.st_mode & S_IFDIR);
-
-	memset(isnull, false, sizeof(isnull));
+	isnull[4] = true;
+#else
+	isnull[3] = true;
+	values[4] = TimestampTzGetDatum(time_t_to_timestamptz(fst.st_ctime));
+#endif
+	values[5] = BoolGetDatum(fst.st_mode & S_IFDIR);
 
 	tuple = heap_form_tuple(tupdesc, values, isnull);
 
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
index abbcc2522c7..3b3b792847d 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -37,7 +37,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.299 2005/08/15 16:25:18 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.300 2005/08/15 23:00:14 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -53,6 +53,6 @@
  */
 
 /*							yyyymmddN */
-#define CATALOG_VERSION_NO	200508151
+#define CATALOG_VERSION_NO	200508152
 
 #endif
-- 
GitLab