Re: Problem with DBI and placeholders

Lawrence Statton <[email protected]>
Newsgroups gmane.comp.lang.perl.beginners
Message-ID <[email protected]>
On 4/9/21 7:11 AM, mailing lists via beginners wrote:
> thanks Andrew
> 
> I need to insert millions of rows so I need to have a good performance 
> using placeholders
> 
> 

You can not use placeholders for the table name.

If you have millions of *tables*, there is something very, very, very 
wrong with your database design.

"Premature optimization is the root of all evil" -- do you have hard 
numeric evidence that the time to create the statement-handle is the 
bottleneck in your system, or are you leaping to the conclusion that you 
"need" to parameterize the table name?

If you have only a few dozen tables, and you need the same statement for 
all of them, then something like

my %sth_for_table;
for my $table qw / foo bar baz waldo pepper salt pork … chains/ {
   $sth_for_table{$table} = $dbh->prepare("whatever whatever into $table");

}

then use the appropriate $sth from the hash for your execute.

That said:  Needing to parameterize the *table name* is an absolute sure 
sign that "You're doing it wrong"


-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.