简体   繁体   中英

knex js - column is of type timestamp but expression is of type character varying

I am selecting rows from tableA and inserting the resulting rows into tableB , using knexJS . Both tableA and tableB have identical schemas in a Redshift database.

Columns names and types

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

Code


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

Error

This code runs into the error below

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

How to fix this in code? Updating db connection properties would be very very difficult for many reasons.

Any leads/help/suggestions will be appreciated

Maybe you are trying to do this:

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

outputs:

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

https://runkit.com/embed/k1vzjp5sdwlj

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM