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

From Peter Haworth
Subject Re: moving from mySQL to pgsql, need a bit of help (perl)
Date
Msg-id ML-3.4.963318699.886.pmh@edison.ioppublishing.com
Whole thread Raw
In response to Re: moving from mySQL to pgsql, need a bit of help (perl)  (Ed Loehr <eloehr@austin.rr.com>)
List pgsql-general
Ed Loehrwrote:
> I believe DBI/DBD does this for you:
>
> while ($row_href = $sth->fetchrow_hashref)
> {
>    push( @taghash, $row_href);
> }

Don't do that! Each hashref in that array will point to the same hash in some
future version of the DBI. You should do this instead:

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

Or, better yet:

  $taghash=$sth->fetchall_arrayref({});

to get everything all in one go.

--
    Peter Haworth    pmh@edison.ioppublishing.com
"Master, does Emacs have the Buddha nature?" the novice asked.
The Chief Priest had been in the temple for many years and could be
relied upon to know these things.  He thought for several minutes before
replying, "I don't see why not.  It's got bloody well everything else."


pgsql-general by date:

Previous
From: The Hermit Hacker
Date:
Subject: Re: Slashdot discussion
Next
From: Andrew Sullivan
Date:
Subject: Re: Slashdot discussion