Re: [HACKERS] pg_stat_file() and length/size - Mailing list pgsql-patches
From | Bruce Momjian |
---|---|
Subject | Re: [HACKERS] pg_stat_file() and length/size |
Date | |
Msg-id | 200508152304.j7FN4Z121068@candle.pha.pa.us Whole thread Raw |
List | pgsql-patches |
Bruce Momjian wrote: > I am thinking the proper term for the first column of pg_stat_file() is > "size", not "length". > > test=> select * from pg_stat_file('.'); > length | atime | mtime | ctime | isdir > --------+------------------------+------------------------+------------------------+------- > > 512 | 2005-08-13 23:06:38-04 | 2005-08-13 23:06:54-04 | 2005-08-13 23:06:54-04 | t > (1 row) I have renamed the column from length to size. I also renamed the timestamp columns to be more meaningful: test=> select (pg_stat_file('.')).*; size | access | modification | change | creation | isdir ------+------------------------+------------------------+------------------------+----------+------- 512 | 2005-08-15 18:10:10-04 | 2005-08-15 17:30:28-04 | 2005-08-15 17:30:28-04 | | t (1 row) (Anyone have a better name for "change"?) In doing this I also realized the ctime on Unix is change time (file contents or inode), while on Win32 ctime is file creation time. I split the ctime column into "change" and "creation", and one is null on each platform. Above is the Unix output. I have also updated the catalog version. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 Index: doc/src/sgml/func.sgml =================================================================== RCS file: /cvsroot/pgsql/doc/src/sgml/func.sgml,v retrieving revision 1.280 diff -c -c -r1.280 func.sgml *** doc/src/sgml/func.sgml 13 Aug 2005 19:02:32 -0000 1.280 --- doc/src/sgml/func.sgml 15 Aug 2005 22:35:59 -0000 *************** *** 9414,9425 **** </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: <programlisting> SELECT * FROM pg_stat_file('filename'); ! SELECT (pg_stat_file('filename')).mtime; </programlisting> </para> --- 9414,9426 ---- </indexterm> <para> <function>pg_stat_file()</> returns a record containing the file ! 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')).modification; </programlisting> </para> Index: src/backend/catalog/system_views.sql =================================================================== RCS file: /cvsroot/pgsql/src/backend/catalog/system_views.sql,v retrieving revision 1.20 diff -c -c -r1.20 system_views.sql *** src/backend/catalog/system_views.sql 15 Aug 2005 16:25:17 -0000 1.20 --- src/backend/catalog/system_views.sql 15 Aug 2005 22:35:59 -0000 *************** *** 346,353 **** 'timestamptz', 'timestamptz', 'timestamptz', 'bool'], ! proargmodes = ARRAY['i'::"char", 'o', 'o', 'o', 'o', 'o'], ! proargnames = ARRAY['filename'::text, ! 'length', 'atime', 'mtime', 'ctime','isdir'] WHERE oid = 'pg_stat_file(text)'::regprocedure; --- 346,354 ---- 'timestamptz', 'timestamptz', 'timestamptz', + 'timestamptz', 'bool'], ! 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; Index: src/backend/utils/adt/genfile.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/utils/adt/genfile.c,v retrieving revision 1.4 diff -c -c -r1.4 genfile.c *** src/backend/utils/adt/genfile.c 13 Aug 2005 19:02:34 -0000 1.4 --- src/backend/utils/adt/genfile.c 15 Aug 2005 22:36:00 -0000 *************** *** 154,161 **** text *filename_t = PG_GETARG_TEXT_P(0); char *filename; struct stat fst; ! Datum values[5]; ! bool isnull[5]; HeapTuple tuple; TupleDesc tupdesc; --- 154,161 ---- text *filename_t = PG_GETARG_TEXT_P(0); char *filename; struct stat fst; ! Datum values[6]; ! bool isnull[6]; HeapTuple tuple; TupleDesc tupdesc; *************** *** 175,200 **** * 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); TupleDescInitEntry(tupdesc, (AttrNumber) 1, ! "length", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, ! "atime", TIMESTAMPTZOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 3, ! "mtime", TIMESTAMPTZOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 4, ! "ctime", TIMESTAMPTZOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 5, "isdir", BOOLOID, -1, 0); BlessTupleDesc(tupdesc); 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)); values[3] = TimestampTzGetDatum(time_t_to_timestamptz(fst.st_ctime)); ! values[4] = BoolGetDatum(fst.st_mode & S_IFDIR); ! ! memset(isnull, false, sizeof(isnull)); tuple = heap_form_tuple(tupdesc, values, isnull); --- 175,209 ---- * 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(6, false); TupleDescInitEntry(tupdesc, (AttrNumber) 1, ! "size", INT8OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, ! "access", TIMESTAMPTZOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 3, ! "modification", TIMESTAMPTZOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 4, ! "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)); ! 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); Index: src/include/catalog/catversion.h =================================================================== RCS file: /cvsroot/pgsql/src/include/catalog/catversion.h,v retrieving revision 1.299 diff -c -c -r1.299 catversion.h *** src/include/catalog/catversion.h 15 Aug 2005 16:25:18 -0000 1.299 --- src/include/catalog/catversion.h 15 Aug 2005 22:36:01 -0000 *************** *** 53,58 **** */ /* yyyymmddN */ ! #define CATALOG_VERSION_NO 200508151 #endif --- 53,58 ---- */ /* yyyymmddN */ ! #define CATALOG_VERSION_NO 200508152 #endif
pgsql-patches by date: