X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2BADBDA1A0 for ; Fri, 11 Nov 2005 18:52:04 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 04489-01 for ; Fri, 11 Nov 2005 22:51:59 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from toq3-srv.bellnexxia.net (toq3-srv.bellnexxia.net [209.226.175.16]) by svr1.postgresql.org (Postfix) with ESMTP id 175CADA09C for ; Fri, 11 Nov 2005 18:51:59 -0400 (AST) Received: from acer.sympatico.ca ([65.95.169.58]) by tomts40-srv.bellnexxia.net (InterMail vM.5.01.06.10 201-253-122-130-110-20040306) with ESMTP id <20051111213435.FZIN1799.tomts40-srv.bellnexxia.net@acer.sympatico.ca> for ; Fri, 11 Nov 2005 16:34:35 -0500 Message-Id: <5.2.1.1.0.20051111161921.05972bf0@pop6.sympatico.ca> X-Sender: b1wudu74@pop6.sympatico.ca X-Mailer: QUALCOMM Windows Eudora Version 5.2.1 Date: Fri, 11 Nov 2005 16:31:35 -0500 To: pgsql-sql@postgresql.org From: Frank Bax Subject: Re: cli in sql? In-Reply-To: <1bb9fe33ef04362819dae06d5326b2ac@biglumber.com> References: <5.2.1.1.0.20051111085132.04119120@pop6.sympatico.ca> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.085 required=5 tests=[AWL=0.085] X-Spam-Score: 0.085 X-Spam-Level: X-Archive-Number: 200511/107 X-Sequence-Number: 23358 At 03:03 PM 11/11/05, Greg Sabino Mullane wrote: >At 08:57 AM 11/11/05, Frank Bax wrote: > > If my database has column containing a filename, can I use sql to present > > this filename and datemodified (as output from 'ls -l' or from mtime() > > fuction) or *must* it be done after the query in interface such as php > or perl? > >Neither. You can do it inside the db with a "pl" language such as plperlu: > >CREATE OR REPLACE FUNCTION filemodtime(TEXT) RETURNS TEXT LANGUAGE plperlu AS >$$ >my $filename = shift; >-e $filename or elog(ERROR, qq{The file "$filename" does not exist\n}); >return localtime($^T - (60*60*24* -M _)); >$$; > >SELECT filemodtime('/var/log/messages'); >SELECT filemodtime('/dark/matter'); This looks interesting! But I'm not sure how to use it? wbax=> select version(); version --------------------------------------------------------------------- PostgreSQL 7.4.3 on i386-unknown-openbsd3.6, compiled by GCC 2.95.3 (1 row) wbax=> CREATE OR REPLACE FUNCTION filemodtime(TEXT) RETURNS TEXT LANGUAGE plperlu AS wbax-> $$ wbax-> my $filename = shift; ERROR: syntax error at or near "$" at character 80 wbax=> -e $filename or elog(ERROR, qq{The file "$filename" does not exist\n}); Invalid command \n});. Try \? for help. wbax(> return localtime($^T - (60*60*24* -M _)); wbax(> $$; wbax(> My system does have /usr/local/lib/postgresql/plperl.so And I tried changing plperlu to plperl, but get the same error. I found: http://www.netcraft.com.au/geoffrey/postgresql/plperl.html to add the language to my system, but that didn't help either.