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

From: Matt Housh <jaeger(at)morpheus(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: moving from mySQL to pgsql, need a bit of help (perl)
Date: 2000-07-10 15:40:52
Message-ID: 3969EE84.1C960D59@morpheus.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hello, I'm trying to move from mySQL to PostgreSQL, and I've got to port a
web app over that's written in perl. It uses the DBD/DBI stuff, and works
great so far with mySQL. I've got a very specific question relating to
pulling data out of a database, I hope this is the correct forum for it.
Here goes:

I have a database set up with a table that has 3 fields in it:

userid
username
userdata

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...

Thanks,
Matt (jaeger(at)morpheus(dot)net)

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ed Loehr 2000-07-10 15:47:57 Re: moving from mySQL to pgsql, need a bit of help (perl)
Previous Message Thomas Lockhart 2000-07-10 15:39:54 Re: Re: [GENERAL] PostgreSQL vs. MySQL