Re: writing to external file - Mailing list pgsql-novice

From Patrick Hatcher
Subject Re: writing to external file
Date
Msg-id OF4F462FD9.D229E646-ON88256C3F.0047B40F@fds.com
Whole thread Raw
In response to writing to external file  ("Thomas_Fahey" <Thomas_Fahey@msn.com>)
List pgsql-novice
Here's a PERL script that someone on this NG kindly helped me with.

#!/usr/bin/perl
use DBI;

# Assign variables

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

&GetUPCs;


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,
$upc18d,$upcflag,$pageflag,$pageid,$dept,$division,$upc,$vend)
= $query->fetchrow_array) {
     print FILE
"$upcid\t$upc18d\t$upcflag\t$pageflag\t$pageid\t$dept\t$division\t$upc\t$vend\n";
                        }
                        close FILE or die "Cannot close $file: $!";
                        $myDate =localtime(time);
                        print (LOGFILE "$myDate Finished Query pull for FTP
upload\n");
                }

                undef $query;
  }


Patrick Hatcher
Macys.Com






    
                    "Thomas_Fahey"
    
                    <Thomas_Fahey@msn.com>        To:     <pgsql-novice@postgresql.org>
    
                    Sent by:                      cc:
    
                    pgsql-novice-owner@post       Subject:     Re: [NOVICE] writing to external file
    
                    gresql.org
    

    

    
                    09/25/2002 05:54 AM
    
                    Please respond to
    
                    "Thomas_Fahey"
    

    

    




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.

Thanks




pgsql-novice by date:

Previous
From: "Thomas_Fahey"
Date:
Subject: Re: writing to external file
Next
From: "Steinn E. Sigurdarson"
Date:
Subject: pgcrypto?