如何在SQL::Abstract/DBIx::Class设置sqlt_datatype?

How to set sqlt_datatype at SQL::Abstract/DBIx::Class?

我不能写这个条件:app_period => { '@>' => '2021-03-15' } 因为我得到一个错误:

malformed range literal: "2021-03-15"

我的查询如下所示:

->search( $cond, @_ )->as_query
  \[
      (SELECT "me"."id", "me"."order_id", "me"."resource_type_id", "me"."service_type_id", "me"."amount", "me"."allocated_resource_id", "me"."last_used", "me"."app_period", "me"."sort_order" FROM "order_detail" "me" WHERE ( ( "app_period" @> ? AND "order_id" = ? ) )),
      [
        {
          dbic_colname => app_period,
          sqlt_datatype => tstzrange,
        },
        2021-03-15,
      ],
      [
        {
          dbic_colname => order_id,
          sqlt_datatype => integer,
        },
        11961,
      ],
    ]

我已经找到 this documentaion 并尝试过:

{ app_period => { '@>' => [ \'timestamptz' => '2021-03-15' ] } }

但出现错误:column "timestamptz" does not exist

如何设置正确的 sqlt_datatype 绑定值?

我似乎找到了完成此操作的方法。我应该将这个散列传递给 ->search(...):

{ app_period => \[ '@> ?::timestamptz', [ { sqlt_datatype => 'timestamptz ' },  '2021-03-15' ] ] }
{ app_period => \[ '@> ?::timestamptz', [ \'timestamptz'                     => '2021-03-15' ] ] }

然后我会得到想要的结果:

\[
    (SELECT "me"."id", "me"."order_id", "me"."resource_type_id", "me"."service_type_id", "me"."amount", "me"."allocated_resource_id", "me"."last_used", "me"."app_period", "me"."sort_order" FROM "order_detail" "me" WHERE ( ( "app_period" @> ?::timestamptz ) )),
    [
      {
        sqlt_datatype => timestamptz,
      },
      2021-03-15,
    ],
  ]

我应该代替值传递 ARRAYREFdoc

[ $name => $val ] === [ { dbic_colname  => $name }, $val ]
[ $dt  => $val ] === [ { sqlt_datatype => $dt   }, $val ]
[ undef,   $val ] === [ {}, $val ]
$val              === [ {}, $val ]

其中 [ {}, $val ] 是通知 section

我仍然没有更改 bindtype,可能是 DBIx::Class 更改了。