Обсуждение: perl DBI::Pg metacharacter \i com_list.sql

Поиск
Список
Период
Сортировка

perl DBI::Pg metacharacter \i com_list.sql

От
ann hedley
Дата:
Hi

in pgsql I can execute a list of sql commands from a text file using ...

    lumbribasetest=# \i comm_list.sql

but in a perl script using DBI and the syntax...

    $com = $conn->prepare("\i comm_list.sql");
    $com->execute() or die $com->errstr;

I get the following error

    DBD::Pg::st execute failed: ERROR:  parser: parse error at or near
"i" at character 1 at /home/ann/bin/pg_go2slim.pl line 85.
    ERROR:  parser: parse error at or near "i" at character 1 at
/home/ann/bin/pg_go2slim.pl line 85.

Anyone know what the syntax should be?

Thanks in advance

--
Ann

"In a world without walls and fences - who needs Windows and Gates ?"
                                                           (unknown)



Re: perl DBI::Pg metacharacter \i com_list.sql

От
"Greg Sabino Mullane"
Дата:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


> $com = $conn->prepare("\i comm_list.sql");
> $com->execute() or die $com->errstr;
>
> Anyone know what the syntax should be?

\i is a feature specific to psql, and is not used by DBD::Pg
(or anything else, for that matter). If what you are doing is
trying to run a collection of commands that are saved in a file,
you should use do() and normal perl file reading:

open(F, "$file") or die qq{Could not open the file "$file": $!\n};
while(<F>) {
        $dbh->do($_);
}

This assumes each line is a valid, self-contained SQL command, of course.

- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200509292033
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8

-----BEGIN PGP SIGNATURE-----

iD8DBQFDPIgKvJuQZxSWSsgRAqamAKDLO/aCQ6fH9bAAVYsRnVhb6P6QQQCg3YII
8773ggJIZYIQHaZXrWQm8N8=
=ekRH
-----END PGP SIGNATURE-----