Обсуждение: Problem in 'select' from temp table with Perl/DBI

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

Problem in 'select' from temp table with Perl/DBI

От
samik@cae.wisc.edu (Samik Raychaudhuri)
Дата:
Hi,
I am using a temp table for a 'select' statement from a perl code
(using DBI) as follows:
==========================================
$query="select date_part('month', date) as month, date_part('year',
date) as year into temp counter from weblogs;
        select month || '-' || year, count(*) from counter group by
month, year;
        ";
$sth=$dbh->prepare($query) || die "Content-type:
text/plain\n\nCouldn't prepare select query: $query\n";
$sth->execute() || die "Content-type: text/plain\n\nCouldn't execute
statement: $query\n";
while(@data=$sth->fetchrow_array()){    push(@Datelog, [$data[0],
$data[1]]);   }
======================================

When I run this code, I get the following error message:
DBD::Pg::st execute failed: ERROR:  Relation 'counter' does not exist
at counter.pl line 56.
Content-type: text/plain

Couldn't execute statement:
select date_part('month', date) as month, date_part('year', date) as
year into temp counter from weblogs;
select month || '-' || year, count(*) from counter group by month,
year;

Line 56 is the 2nd select statement.
Can anybody give a hint about what can be wrong here?
Thanks and regards.
Samik

Re: Problem in 'select' from temp table with Perl/DBI

От
Tom Lane
Дата:
samik@cae.wisc.edu (Samik Raychaudhuri) writes:
> $query="select date_part('month', date) as month, date_part('year',
> date) as year into temp counter from weblogs;
>         select month || '-' || year, count(*) from counter group by
> month, year;
>         ";

> When I run this code, I get the following error message:
> DBD::Pg::st execute failed: ERROR:  Relation 'counter' does not exist
> at counter.pl line 56.

You didn't say what postgres version you are using, but on older
versions I think it'd be necessary to issue those commands as two
separate statements.  PG used to try to parse all the commands in
a querystring before executing any of them.

            regards, tom lane