【问题标题】:knex js - column is of type timestamp but expression is of type character varyingknex js - 列的类型是时间戳,但表达式的类型是字符变化
【发布时间】:2020-12-28 00:26:15
【问题描述】:

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

列名和类型

  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

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

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

【问题讨论】:

    标签: javascript sql postgresql amazon-redshift knex.js


    【解决方案1】:

    也许你正在尝试这样做:

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

    输出:

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

    https://runkit.com/embed/k1vzjp5sdwlj

    【讨论】:

      猜你喜欢
      • 2019-11-08
      • 2015-11-26
      • 1970-01-01
      • 1970-01-01
      • 2021-06-18
      • 2020-02-17
      • 2015-11-09
      • 2015-05-30
      • 2023-03-14
      相关资源
      最近更新 更多