Commit 070a3ad7 authored by Bruce Momjian's avatar Bruce Momjian

Rename pg_stat_file columns to be more consistent. Split apart change

and creation columns to behave for Unix or Win32.
parent 24bd9447
<!-- <!--
$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 PostgreSQL documentation
--> -->
...@@ -9414,12 +9414,13 @@ SELECT set_config('log_statement_stats', 'off', false); ...@@ -9414,12 +9414,13 @@ SELECT set_config('log_statement_stats', 'off', false);
</indexterm> </indexterm>
<para> <para>
<function>pg_stat_file()</> returns a record containing the file <function>pg_stat_file()</> returns a record containing the file
length, last accessed timestamp, last modified timestamp, size, last accessed timestamp, last modified timestamp,
creation timestamp, and a boolean indicating if it is a directory. last file status change timestamp (Unix platforms only),
Typical usages include: file creation timestamp (Win32 only), and a boolean indicating
if it is a directory. Typical usages include:
<programlisting> <programlisting>
SELECT * FROM pg_stat_file('filename'); SELECT * FROM pg_stat_file('filename');
SELECT (pg_stat_file('filename')).mtime; SELECT (pg_stat_file('filename')).modification;
</programlisting> </programlisting>
</para> </para>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 1996-2005, PostgreSQL Global Development Group * 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 CREATE VIEW pg_roles AS
...@@ -346,8 +346,9 @@ UPDATE pg_proc SET ...@@ -346,8 +346,9 @@ UPDATE pg_proc SET
'timestamptz', 'timestamptz',
'timestamptz', 'timestamptz',
'timestamptz', 'timestamptz',
'timestamptz',
'bool'], 'bool'],
proargmodes = ARRAY['i'::"char", 'o', 'o', 'o', 'o', 'o'], proargmodes = ARRAY['i'::"char", 'o', 'o', 'o', 'o', 'o', 'o'],
proargnames = ARRAY['filename'::text, proargnames = ARRAY['filename'::text, 'size', 'access', 'modification',
'length', 'atime', 'mtime', 'ctime','isdir'] 'change', 'creation', 'isdir']
WHERE oid = 'pg_stat_file(text)'::regprocedure; WHERE oid = 'pg_stat_file(text)'::regprocedure;
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Author: Andreas Pflug <pgadmin@pse-consulting.de> * Author: Andreas Pflug <pgadmin@pse-consulting.de>
* *
* IDENTIFICATION * 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) ...@@ -154,8 +154,8 @@ pg_stat_file(PG_FUNCTION_ARGS)
text *filename_t = PG_GETARG_TEXT_P(0); text *filename_t = PG_GETARG_TEXT_P(0);
char *filename; char *filename;
struct stat fst; struct stat fst;
Datum values[5]; Datum values[6];
bool isnull[5]; bool isnull[6];
HeapTuple tuple; HeapTuple tuple;
TupleDesc tupdesc; TupleDesc tupdesc;
...@@ -175,26 +175,35 @@ pg_stat_file(PG_FUNCTION_ARGS) ...@@ -175,26 +175,35 @@ pg_stat_file(PG_FUNCTION_ARGS)
* This record type had better match the output parameters declared * This record type had better match the output parameters declared
* for me in pg_proc.h (actually, in system_views.sql at the moment). * 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, TupleDescInitEntry(tupdesc, (AttrNumber) 1,
"length", INT8OID, -1, 0); "size", INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 2, TupleDescInitEntry(tupdesc, (AttrNumber) 2,
"atime", TIMESTAMPTZOID, -1, 0); "access", TIMESTAMPTZOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 3, TupleDescInitEntry(tupdesc, (AttrNumber) 3,
"mtime", TIMESTAMPTZOID, -1, 0); "modification", TIMESTAMPTZOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 4, TupleDescInitEntry(tupdesc, (AttrNumber) 4,
"ctime", TIMESTAMPTZOID, -1, 0); "change", TIMESTAMPTZOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 5, TupleDescInitEntry(tupdesc, (AttrNumber) 5,
"creation", TIMESTAMPTZOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 6,
"isdir", BOOLOID, -1, 0); "isdir", BOOLOID, -1, 0);
BlessTupleDesc(tupdesc); BlessTupleDesc(tupdesc);
memset(isnull, false, sizeof(isnull));
values[0] = Int64GetDatum((int64) fst.st_size); values[0] = Int64GetDatum((int64) fst.st_size);
values[1] = TimestampTzGetDatum(time_t_to_timestamptz(fst.st_atime)); values[1] = TimestampTzGetDatum(time_t_to_timestamptz(fst.st_atime));
values[2] = TimestampTzGetDatum(time_t_to_timestamptz(fst.st_mtime)); 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[3] = TimestampTzGetDatum(time_t_to_timestamptz(fst.st_ctime));
values[4] = BoolGetDatum(fst.st_mode & S_IFDIR); isnull[4] = true;
#else
memset(isnull, false, sizeof(isnull)); 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); tuple = heap_form_tuple(tupdesc, values, isnull);
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * 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 @@ ...@@ -53,6 +53,6 @@
*/ */
/* yyyymmddN */ /* yyyymmddN */
#define CATALOG_VERSION_NO 200508151 #define CATALOG_VERSION_NO 200508152
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment