rosenk
Programmer
- Jan 16, 2003
- 403
Is there a good way to retrieve the value of array type columns as a perl list?
Here's an example:
[tt]CREATE TABLE test (
Names VARCHAR(16)[]
};
INSERT INTO test VALUES ('{"Bob", "Dave"}');[/tt]
I'd like to retrieve the row from the database and end up with a perl list containing the individual values "Bob" and "Dave". My usual:
[tt]$sth = $dbh->prepare("SELECT Names FROM test"
$sth->execute;
$sth->bind_columns(\$names);
$sth->fetch;[/tt]
results in $names containing the string '{"Bob", "Dave"}'. I tried using the line:
[tt]$sth->bind_columns(\@names);[/tt]
but you're not allowed to bind to a list, only a scalar.
Any ideas?
(I'd post in the perl forum, but array type columns seems fairly PostgreSQL specific.)
Here's an example:
[tt]CREATE TABLE test (
Names VARCHAR(16)[]
};
INSERT INTO test VALUES ('{"Bob", "Dave"}');[/tt]
I'd like to retrieve the row from the database and end up with a perl list containing the individual values "Bob" and "Dave". My usual:
[tt]$sth = $dbh->prepare("SELECT Names FROM test"
$sth->execute;
$sth->bind_columns(\$names);
$sth->fetch;[/tt]
results in $names containing the string '{"Bob", "Dave"}'. I tried using the line:
[tt]$sth->bind_columns(\@names);[/tt]
but you're not allowed to bind to a list, only a scalar.
Any ideas?
(I'd post in the perl forum, but array type columns seems fairly PostgreSQL specific.)