That is partially correct. For example, PostgreSQL supports arrays. In that case, you use an array reference to put it into a single placeholder.

Ok, lets make a test table:

CREATE TABLE arraytesttable ( array_id text NOT NULL, array_values text[] NOT NULL, CONSTRAINT arraytesttable_pk PRIMARY KEY (array_id) ) WITH ( OIDS = FALSE );

Now, we use Perl to insert some rows:

#!/usr/bin/perl use strict; use warnings; use DBI; my $dbh = DBI->connect("dbi:Pg:dbname=MY_DB;host=localhost", 'MY_Server', 'VERYSECRET', {AutoCommit => 0}) or die("Can't connect"); my $sth = $dbh->prepare_cached("INSERT INTO arraytesttable (array_id, array_values) VALUES (?, ?)") or die($dbh->errstr); my @english = qw(Hello world); my @german = qw(Hallo Welt); $sth->execute('ger', \@german) or die($dbh->errstr); $sth->execute('eng', \@english) or die($dbh->errstr); $dbh->commit;

That worked very beautifull, now let's read the values back. First all rows, then by finding the languages when we know the full translation (e.g. selecting by array):

#!/usr/bin/perl use strict; use warnings; use DBI; my $dbh = DBI->connect("dbi:Pg:dbname=MY_DB;host=localhost", 'MY_Server', 'VERYSECRET', {AutoCommit => 0}) or die("Can't connect"); # SELECT ALL ROWS my $fullsth = $dbh->prepare_cached("SELECT array_id, array_values FROM arraytesttable") or die($dbh->errstr); $fullsth->execute or die($dbh->errstr); while((my $line = $fullsth->fetchrow_hashref)) { print $line->{array_id} . ': ' . join(',', @{$line->{array_values} +}) . "\n"; } $fullsth->finish; # SELECT BY ARRAY my $arrsth = $dbh->prepare_cached("SELECT array_id, array_values FROM arraytesttable WHERE array_values = ?") or die($dbh->errstr); my @german = qw(Hallo Welt); $arrsth->execute(\@german) or die($dbh->errstr); while((my $line = $arrsth->fetchrow_hashref)) { print $line->{array_id} . ': ' . join(',', @{$line->{array_values} +}) . "\n"; } $arrsth->finish; $dbh->rollback;

As expected, this outputs:

ger: Hallo,Welt eng: Hello,world ger: Hallo,Welt

So, we established that the single value in single column statement doesn't hold true. PostgreSQL allows a single column holds an array model, which DBD::Pg allows us to use through array references.

Don't use '#ff0000':
use Acme::AutoColor; my $redcolor = RED();
All colors subject to change without notice.

In reply to Re^2: DBD::SQLite, how to pass array in query via placeholder? by cavac
in thread DBD::SQLite, how to pass array in query via placeholder? by dwalin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.