postgresql - 如何使用 perl 插入 tsrange

标签 postgresql perl dbi

我正在使用 DBD::Pg 尝试创建一个带有绑定(bind)变量的插入语句,其中一个是 tsrange。我不断收到语法错误,有人可以解释一下正确的方法吗?

来自 perl 脚本:

$sth->{'insert'}->execute($hashRef->{'<NUMBER>'}
                                    , $hashRef->{'<FIRSTNAME>'}
                                    , $hashRef->{'<LASTNAME>'}
                                    , $hashRef->{'<DATEIN>'} . ' ' .       $hashRef->{'<TIMEIN>'}
                                    , $hashRef->{'<DATEOUT>'} . ' ' .  $hashRef->{'<TIMEOUT>'}
                                    , $hashRef->{'<JOBCODE>'} 
                                    , $hashRef->{'<JOBCODEDESC>'} 
                                    , $hashRef->{'<COSTCODELEVEL1>'} 
                                    , $hashRef->{'<COSTCODELEVEL2>'} 
                                    , $hashRef->{'<COSTCODELEVEL3>'} 
                                    , $hashRef->{'<DEPARTMENT>'} 
            )or die $DBI::errstr;
    enter code here 

来自配置文件:

sql:
    insert: |-
        insert into etl.timeclock_plus values (
           ? 
         , ? 
         , ?  
         , [ ? , ? ] 
         , ? 
         , ? 
         , ? 
         , ? 
         , ?
         , ? 
        )   
The error : 
syntax error at or near "$4"

最佳答案

代替

[ $1, $2 ]

这是无效的 SQL,使用范围构造函数:

tstzrange($1, $2, '[)')

如果您需要这些数据类型,还有 tsrangedaterange

关于postgresql - 如何使用 perl 插入 tsrange,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58288990/

相关文章:

mysql - 使用 gem 'dbi' 与 ruby​​ 的 Mysql DB 连接问题

c# - 在 PostgreSQL 中生成用于将 IPAddress 映射为 INET 类型的表?

java - 关于使用 FileInputStream 上的 PreparedStatement.setBlob 到具有 Bytea 类型的 postgres 数据库的问题

ruby-on-rails - db :reset 后 Postgres 函数未保留

mysql - 如何通过 DBI 重新使用 WHERE 子句逻辑?

Perl DBI 在嵌套 sql 上的性能

sql - 通过 Excel 2016 上的 ODBC 连接到 PostgreSQL 数据库

java - Runtime.getRuntime().exec 奇怪的行为

linux - 从 perl 网络服务器访问用户文件

database - 如何使用 Perl 连接到 MS Access 数据库?