postgresql框类型的占位符,使用DBI / DBD :: PG

时间:2014-10-16 08:59:55

标签: perl postgresql placeholder dbi

我正在尝试使用占位符将几何类型插入到postgresql数据库中。

我尝试了以下两个代码:

my $sth = ($dbh)->prepare("INSERT INTO lrad.matable(zone) VALUES (BOX'((?,?),(?,?))');"); 
$sth->execute(0.5,0.7,0.4,0.6);

会产生DBD::Pg::st execute failed: called with 4 bind variables when 0 are needed

my $sth = ($dbh)->prepare("INSERT INTO lrad.matable(zone) VALUES (((?,?),(?,?)));"); 
$sth->execute(0.5,0.7,0.4,0.6);

会产生column "zone" is of type box but expression is of type record HINT: You will need to rewrite or cast the expression.

有任何解决方法吗?或者我会强行建立没有占位符的盒子吗?

1 个答案:

答案 0 :(得分:1)

使用函数而不是强制转换来构建框:

INSERT INTO lrad.matable(zone) VALUES (box(point(?,?),point(?,?)))

你也可以建立字符串"(0.5,0.7),(0.4,0.6)"在perl中,并将该字符串传递给一个?占位符:

    INSERT INTO lrad.matable(zone) VALUES (?::box)