Вопрос по perl, postgresql – Как я могу использовать запрос с заполнителем внутри кавычек? (perl / postgresql)

4

Error: User Rate Limit Exceeded

#!/usr/bin/perl -w

use strict;
use DBI;

my $db = "Pg";
my $db_database = "whatever";
my $user = "whatever";
my $password = "whatever";

my $dbh = DBI->connect("dbi:$db:dbname=$db_database", $user, $password);

my $query = $dbh->prepare (q{SELECT
                   arrival_date - INTERVAL '? MINUTE'
                   FROM emails LIMIT 1})
  or die ("unable to prepare");
$query->execute(60) or die("unable to execute");

print $query->fetchrow_array, "\n";

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

DBD::Pg::st execute failed: called with 1 bind variables when 0 are needed 

Error: User Rate Limit Exceeded

Ваш Ответ

3   ответа
9

my $query = $dbh->prepare (q{SELECT
                   arrival_date - ? * INTERVAL '1 MINUTE'
                   FROM emails LIMIT 1});
$query->execute(60);

' minutes'

Error: User Rate Limit Exceeded atlau
2
my $query = $dbh->prepare (<<SQL) or die ("unable to prepare");
SELECT arrival_date - INTERVAL ? FROM emails LIMIT 1
SQL
$query->execute("60 MINUTE");

or

my $query = $dbh->prepare (<<SQL) or die ("unable to prepare");
SELECT arrival_date - INTERVAL CONCAT(?, " MINUTE") FROM emails LIMIT 1
SQL
$query->execute(60);

Error: User Rate Limit Exceeded atlau
3

my $query = $dbh->prepare (q{SELECT
                   arrival_date - ?::interval
                   FROM emails LIMIT 1});

$query->execute('60 MINUTE');

Похожие вопросы