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: OF4F462FD9.D229E646-ON88256C3F.0047B40F@fds.com (view raw or flat)
Thread:
Lists: 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(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                        
                    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

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-2014 The PostgreSQL Global Development Group