Thread: writing to external file
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
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
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