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

Re: writing to external file

From: "Patrick Hatcher" <PHatcher(at)macys(dot)com>
To: "Thomas_Fahey" <thomas_fahey(at)msn(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org, pgsql-novice-owner(at)postgresql(dot)org
Subject: Re: writing to external file
Date: 2002-09-25 13:14:42
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Here's a PERL script that someone on this NG kindly helped me with.

use DBI;

# Assign variables

$infile= '/home/ftp/pub/Incoming/postgres/ozupc.txt';


sub GetUPCs
        $dbh = DBI->connect( "dbi:Pg:dbname=mdc_oz", "user", "pwd" )
        or die "Cannot make data connection: $DBI::errstr\n";

        # Send command to not print header or footer information
          $query = $dbh->prepare("select * from upc_export_v;")
                or die "Cannot prepare SQL statement: $DBI::errstr\n";
                $query->execute ;
                if ($query->rows == 0)
                                my $err_msg="Yieks No Data";

                        } else {

                        open (FILE, ">$infile") or die("Can't open
$logfile: $!");
                open (FILE, ">$sqlfile") or die("Can't open $sqlfile: $!");

     while (my ($upcid,
= $query->fetchrow_array) {
     print FILE
                        close FILE or die "Cannot close $file: $!";
                        $myDate =localtime(time);
                        print (LOGFILE "$myDate Finished Query pull for FTP

                undef $query;

Patrick Hatcher

                    <Thomas_Fahey(at)msn(dot)com>        To:     <pgsql-novice(at)postgresql(dot)org>                                     
                    Sent by:                      cc:                                                                       
                    pgsql-novice-owner(at)post       Subject:     Re: [NOVICE] writing to external file                        
                    09/25/2002 05:54 AM                                                                                     
                    Please respond to                                                                                       

Looking for a quick and dirty way to programmatically write to an ASCII
file (not looking for a COPY).

Something similar to utl_file.fopen and utl_file.put_line in Oracle.


pgsql-novice by date

Next:From: Steinn E. SigurdarsonDate: 2002-09-25 14:38:06
Subject: pgcrypto?
Previous:From: Thomas_FaheyDate: 2002-09-25 12:54:38
Subject: Re: writing to external file

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