knex js-列的类型为时间戳,但表达式的类型为字符变化

问题描述

我正在从tableA中选择行,并使用tableB将结果行插入到knexJS中。 tableAtableBRedshift数据库中具有相同的架构。

列名和类型

  1. id - int
  2. created_date - timestamp without timezone

代码


knex(tableB)
  .insert(function() {
      this.select()
          .from(tableA)
          .whereRaw('id=?',['12345']);
  });

错误

代码遇到以下错误

error: column \"created_date\" is of type timestamp without time zone but expression is of type character varying

如何在代码解决此问题?由于许多原因,更新数据库连接属性将非常非常困难。

任何线索/帮助/建议将不胜感激

解决方法

也许您正在尝试这样做:

knex('table1')
  .insert(
    knex.raw("?",[ knex('table2').where('id','12345') ])
  );

输出:

insert into "table1" (select * from "table2" where "id" = ?)

https://runkit.com/embed/k1vzjp5sdwlj