1
2
3
4
5
6
7
8
9
10
11
12
13
$name = "komischer-name";
$dbh->do( "CREATE TABLE $name
(
$name text,
datum time,
CONSTRAINT deeeescr PRIMARY KEY ($name,datum)
)
WITH (
OIDS=FALSE
);
");
$name = $dbh->quote($name);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#!/usr/bin/perl use strict; use warnings; use DBI; my $dbname='xxx'; my $user='anonymous'; my $pass='???'; my $dbh = DBI->connect("dbi:Pg:dbname=$dbname", $user, $pass, {RaiseError => 1, AutoCommit => 1}) or die $DBI::errstr; my $cname='nur-ein-test'; # entwerten von doppelten Anführungszeichen durch verdoppeln, # wenn sie im Spaltennamen vorkommen $cname=~/"/""/gs; # es kann aber dennoch sein, dass fremder Code eingeschleust wird. $dbh->do(qq'CREATE TABLE test ( "$cname" text, datum date, id int )'); $dbh->disconnect();
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/bin/perl use strict; use warnings; use DBI; my $dbname='xxx'; my $user='anonymous'; my $pass='???'; my $dbh = DBI->connect("dbi:Pg:dbname=$dbname", $user, $pass, {RaiseError => 1, AutoCommit => 1}) or die $DBI::errstr; my $cname='nur-ein-test'; $cname = $dbh->quote_identifier($cname); $dbh->do("CREATE TABLE test ( $cname text, datum date, id int )"); $dbh->disconnect();