An internet search didn't show up an example of inserting data into a PostgreSQL array (quite a few for retrieving data, though), so I thought I'd post this here.
Given a table:
create table my_table(
id serial,
description varchar(255),
associated_str_data varchar(255)[],
associated_int_data integer[]);
just using arrayrefs for data supplied to the placeholders does the job:
my $desc = "A description";
my @assoc_str_data = ("string 1", "string 2");
my @assoc_int_data = (1,2,3);
$dbh->do("insert into my_table(description, associated_str_data, assoc
+iated_int_data) values (?,?,?)",
undef, $desc, \@assoc_str_data, \@assoc_int_data);
Checking the result in psql shows the data inserted OK:
# select * from my_table;
id | description | associated_str_data | associated_int_data
----+---------------+-------------------------+---------------------
2 | A description | {"string 1","string 2"} | {1,2,3}
(1 row)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.