Thread: Perl query error

Perl query error

From
"Patrick Hatcher"
Date:
Hello,
I'm trying to use a Perl script to export a query result to a text file.
The result should have no header or footer information.  However, when I
run the script, I get a message: DBD::Pg::st execute failed: ERROR:
parser: parse error at or near "/" at ./mdcupc.pl line 189.

Here's the section where the error occurs:


     # Send command to not print header or footer information
     my $query = $dbh->prepare("\t")
          or die "Cannot prepare SQL statement: $DBI::errstr\n";
          $query->execute ;


     # Send command to not print header or footer information
       $query = $dbh->prepare("select * from upc_export_v  \g
/home/ftp/pub/Incoming/postgres/ozupc.txt;")
          or die "Cannot prepare SQL statement: $DBI::errstr\n";
          $query->execute ;

Any help would be greatly appreciated.

Patrick Hatcher
Macys.Com
Legacy Integration Developer
415-932-0610 office





Re: Perl query error

From
"Joshua b. Jore"
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm at a loss as to why you aren't just using normal SQL like so. Does the
DBD::Pg driver even support those slash commands?

Josh

my $file = '/home/ftp/pub/Incoming/postgres/ozupc.txt';
open FILE, ">$file" or die "Cannot open $file: $!";
$sth = $dbh->prepare("SELECT * FROM upc_export_v");
$sth->execute;
while (my @ary = $sth->fetchrow_array) {
    print FILE join "\t", @ary;
}
undef $sth;
close FILE or die "Cannot close $file: $!";

Joshua b. Jore
http://www.greentechnologist.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (OpenBSD)
Comment: For info see http://www.gnupg.org

iD8DBQE8tHTlfexLsowstzcRApiXAKDfd15lbOKYNfZIDkp36JEGNRK41wCgjhST
r5jwqXdtMcxxDtymBWalwLE=
=61vB
-----END PGP SIGNATURE-----


Re: Perl query error

From
"Patrick Hatcher"
Date:
Thanks for the help Josh.
Way too newbie to know what can or can't be done with DBI.

Patrick Hatcher
Macys.Com
Legacy Integration Developer
415-932-0610 office






                    "Joshua b. Jore"
                    <josh@greentechnol       To:     Patrick Hatcher <PHatcher@macys.com>
                    ogist.org>               cc:     pgsql-novice@postgresql.org
                                             Subject:     Re: [NOVICE] Perl query error
                    04/10/2002 10:22
                    AM






-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm at a loss as to why you aren't just using normal SQL like so. Does the
DBD::Pg driver even support those slash commands?

Josh

my $file = '/home/ftp/pub/Incoming/postgres/ozupc.txt';
open FILE, ">$file" or die "Cannot open $file: $!";
$sth = $dbh->prepare("SELECT * FROM upc_export_v");
$sth->execute;
while (my @ary = $sth->fetchrow_array) {
           print FILE join "\t", @ary;
}
undef $sth;
close FILE or die "Cannot close $file: $!";

Joshua b. Jore
http://www.greentechnologist.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (OpenBSD)
Comment: For info see http://www.gnupg.org

iD8DBQE8tHTlfexLsowstzcRApiXAKDfd15lbOKYNfZIDkp36JEGNRK41wCgjhST
r5jwqXdtMcxxDtymBWalwLE=
=61vB
-----END PGP SIGNATURE-----






Re: Perl query error

From
Andrew McMillan
Date:
On Thu, 2002-04-11 at 05:19, Patrick Hatcher wrote:
>
> Thanks for the help Josh.
> Way too newbie to know what can or can't be done with DBI.

:-)

Use 'psql -E database' to see what the backend SQL is for the commands
psql implements.  Or you could use the source...

Regards,
                    Andrew.
--
--------------------------------------------------------------------
Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington
WEB: http://catalyst.net.nz/        PHYS: Level 2, 150-154 Willis St
DDI: +64(4)916-7201    MOB: +64(21)635-694    OFFICE: +64(4)499-2267
       Are you enrolled at http://schoolreunions.co.nz/ yet?


Re: Perl query error

From
"Joshua b. Jore"
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Actually, one of the main things to keep in mind is that all those slash
commands are only supported by the psql frontend. If you examine
src/backend/parser/gram.y you won't find any of them in there. That means
you don't get to use them when using the DBI interface in perl since that
uses the standard backend interface. Just use that SQL reference in the
docs as a guide for what is allowed (and not).

That said, the -E flag is nice to see how core PostgreSQL developers have
implemented some queries. ;-)

Joshua b. Jore
http://www.greentechnologist.org

On 11 Apr 2002, Andrew McMillan wrote:

> On Thu, 2002-04-11 at 05:19, Patrick Hatcher wrote:
> >
> > Thanks for the help Josh.
> > Way too newbie to know what can or can't be done with DBI.
>
> :-)
>
> Use 'psql -E database' to see what the backend SQL is for the commands
> psql implements.  Or you could use the source...
>
> Regards,
>                     Andrew.
> --
> --------------------------------------------------------------------
> Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington
> WEB: http://catalyst.net.nz/        PHYS: Level 2, 150-154 Willis St
> DDI: +64(4)916-7201    MOB: +64(21)635-694    OFFICE: +64(4)499-2267
>        Are you enrolled at http://schoolreunions.co.nz/ yet?
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (OpenBSD)
Comment: For info see http://www.gnupg.org

iD8DBQE8tZXCfexLsowstzcRAvcBAJ4tf4R4lC3w+Ya0M+trj88Hw2RsSgCdEUUZ
g0/cTkPnjCg6aS5fZwv924Y=
=Ni33
-----END PGP SIGNATURE-----