Re: moving from mySQL to pgsql, need a bit of help (perl)

From: Ed Loehr <eloehr(at)austin(dot)rr(dot)com>
To: Matt Housh <jaeger(at)morpheus(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: moving from mySQL to pgsql, need a bit of help (perl)
Date: 2000-07-10 15:47:57
Message-ID: 3969F02D.244D9B96@austin.rr.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Matt Housh wrote:
>
> In my current code (perl/mySQL), I execute the following query: "SELECT *
> from table_name" - then use the following code to put it in a hash:
>
> $j = 0;
> while (@row = $sth->fetchrow_array)
> {
> for ($i = 0; $i < $fields; $i++)
> {
> $taghash[$j]{$$fieldnames[$i]} = $row[$i];
> }
> $j++;
> }
>
> What I end up with is an array of hashes containing all the table data.
> Each element in the array is a hash called $taghash[$i], and the fields can
> be accessed via $taghash[$i]{'userid'}, $taghash[$i]{'username'}, and
> $taghash[$i]{'userdata'}. $fields and $fieldnames are variables created by a
> subroutine I wrote which is called after the query is executed. $fields is
> simply the number of fields in the table, and $fieldnames is an array
> containing the names of the columns in the table, in order, produced by
> "$fieldnames = $sth->{NAME};" HERE is the problem. The PostgreSQL DBI/DBD
> doesn't seem to support this. I'm looking for something that returns the
> names of the columns in the table, so I can duplicate my code without
> changing too much. Is there anything available to do this? I've yet to find
> it in the documentation, though I may have simply missed it, as I'm new to
> PostgreSQL... Any help is appreciated...

I believe DBI/DBD does this for you:

while ($row_href = $sth->fetchrow_hashref)
{
push( @taghash, $row_href);
}

Regards,
Ed Loehr

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert D. Nelson 2000-07-10 15:49:00 RE: PostgreSQL & the BSD License
Previous Message Matt Housh 2000-07-10 15:40:52 moving from mySQL to pgsql, need a bit of help (perl)