Skip site navigation (1) Skip section navigation (2)

How to get result of a query from MS DOS batch script or delete file from plpgsq

From: "Pham Luu Hung" <hungpl(at)hotmail(dot)com>
To: pgsql-cygwin(at)postgresql(dot)org
Subject: How to get result of a query from MS DOS batch script or delete file from plpgsq
Date: 2004-01-19 05:03:20
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-cygwin
<html><div style='background-color:'><DIV>
<DIV class=RTE>Hi all</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>I'm writing a MS DOS batch script to delete some expired rows from my PostgreSQL DB and also some associated file (which full path is stored in DB).&nbsp; In order to fulfil that, I have to get&nbsp;the date&nbsp;and path from DB, and delete the expired row as well as the file associated with that row. So now 2 have to approaches:</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>1.&nbsp;Write a&nbsp;plpgsql scrip and run it by psql. Inside the plpgsql script I have to delete the file in hard disk, but till now I could not find any way to&nbsp;do that. I do not know whether plpgsql can support some type of file manipulation?&nbsp;</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>2. Delete the file from MS DOS batch script ( it is easier), but I have to pass the query result (which&nbsp;is mostly&nbsp;an array) to the MS DOS batch script.</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>For the second approach, my first try is to output the query result to a text file </DIV>
<DIV class=RTE>(eg: bash -c "psql -d&nbsp;DBname -c "select&nbsp;COLUMN_name from A_table WHERE...;" &gt; result.txt")</DIV>
<DIV class=RTE>but the text file is such a complicated file with name of column and some symbol ----- so it is difficult to extract the result.</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>So do you have any suggestion for my problem? Is there any way to delete file within the plpgsql block, or sending query result to MS DOS script in a convenient way for being &nbsp;processed.</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>Thank you very much. </DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>Regards</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>Pham Luu Hung</DIV></DIV></div><br clear=all><hr>Add photos to your e-mail with <a href="">MSN 8.</a> Get 2 months FREE*.</html>

Attachment: unknown_filename
Description: text/html (1.9 KB)

pgsql-cygwin by date

Next:From: Patrick SamsonDate: 2004-01-19 07:54:55
Subject: Re: Initdb failing when installing Postgre on Cygwin
Previous:From: bsytkoDate: 2004-01-18 01:59:35
Subject: Initdb failing when installing Postgre on Cygwin

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group