Обсуждение: perl and postgres. . .

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

perl and postgres. . .

От
JT Kirkpatrick
Дата:
I'm trying in perl to get a maximum value from a field in a postgres table:
$query="select max(userseq) from dataentry;";
$result=$conn->exec("$query");

and then capture that value in a scalar variable:
    $userseq=($result);

but it's not working.  The field userseq is int4 if that matters to you.
 if I can capture that value in a variable then I can use it in an update
query for that particular record.  Can anyone enlighten me??

jt


Re: [SQL] perl and postgres. . .

От
"Gene Selkov Jr."
Дата:
> I'm trying in perl to get a maximum value from a field in a postgres table:
> $query="select max(userseq) from dataentry;";
> $result=$conn->exec("$query");
>
> and then capture that value in a scalar variable:
>     $userseq=($result);
>
> but it's not working.

$result->getvalue(0, 0)

(pse. read examples in `perldoc Pg`)

Re: [SQL] perl and postgres. . .

От
"Brett W. McCoy"
Дата:
On Wed, 21 Apr 1999, JT Kirkpatrick wrote:

> I'm trying in perl to get a maximum value from a field in a postgres table:
> $query="select max(userseq) from dataentry;";
> $result=$conn->exec("$query");
>
> and then capture that value in a scalar variable:
>     $userseq=($result);
>
> but it's not working.  The field userseq is int4 if that matters to you.
>  if I can capture that value in a variable then I can use it in an update
> query for that particular record.  Can anyone enlighten me??

You can't get row information from a query that way.  You need to use
$result->fetchrow to get the actual data out of your query (it returns
Null if there are no more rows to fetch from). You could do something like:

@q_row = $result->fetchrow;
$userseq = $q_row[0];

To get that information.


Brett W. McCoy
                                         http://www.lan2wan.com/~bmccoy
-----------------------------------------------------------------------
Self Test for Paranoia:
    You know you have it when you can't think of anything that's
your own fault.