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

Поиск
Список
Период
Сортировка
От Matt Housh
Тема moving from mySQL to pgsql, need a bit of help (perl)
Дата
Msg-id 3969EE84.1C960D59@morpheus.net
обсуждение исходный текст
Список 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@morpheus.net)

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [NOVICE] newbie problem on creating table
Следующее
От: Ed Loehr
Дата:
Сообщение: Re: moving from mySQL to pgsql, need a bit of help (perl)