redpanda-data / connect

Fancy stream processing made operationally mundane
https://docs.redpanda.com/redpanda-connect/about/
8.13k stars 833 forks source link

Failed to write output data to ORACLE date type field #2414

Closed vicochan closed 8 months ago

vicochan commented 8 months ago

I have an example of writing output data to an ORALCE table,

the table structure is as follows

create table GZ_MIGRATE_HISTORICAL_30_TEST ( snap_time DATE, city VARCHAR2(20), population_total NUMBER, migrate_total NUMBER, createon DATE default sysdate ) The following table describes the YAML configuration:

pipeline:
  processors:
    - bloblang: |
        root.arr = content().split(",")
        root.snap_time = root.arr.index(0).string().ts_parse("20060102").ts_format("2006-01-02")
        root.city = root.arr.index(1).string()
        root.population_total = root.arr.index(2).int32()
        root.migrate_total = root.arr.index(3).int32()
        root.createon = now()
    - catch:
      - log:
          message: "Processing failed due to: ${!error()}"
output:
  sql_insert:
    driver: oracle
    dsn: oracle://user:password@192.168.1.1:1521/dbname
    table: GZ_MIGRATE_HISTORICAL_30_TEST
    columns:
      - snap_time
      - city
      - population_total
      - migrate_total
      - createon
    args_mapping:
      root = [ this.createon.ts_strftime("%Y-%b-%d %H:%M:%S"),this.city,this.population_total,this.migrate_total,this.createon.ts_strftime("%Y-%b-%d %H:%M:%S")] 

The error message is as follows:

level=error msg="Failed to send message to sql_insert: ORA-01861: literal does not match format string\n" @service=stc label="" path=root.output

Another way to write it

output:
  sql_raw:
    driver: oracle
    dsn: oracle://user:password@192.168.1.1:1521/dbname
    query: |
      INSERT INTO GZ_MIGRATE_HISTORICAL_30_TEST1 (snap_time,city,population_total,migrate_total,createon) VALUES(to_date($1,'yyyy-mm-dd'),$2,$3,$4,to_date($5,'yyyy-mm-dd'));
    args_mapping: |
      root = [
      this.createon,
      this.city,
      this.population_total,
      this.migrate_total,
      this.createon,
      ]

I also want to use the same mistake in another way, what is the syntax for writing the date type field of ORALCE?

Jeffail commented 8 months ago

Converting to a discussion as per https://github.com/benthosdev/benthos/issues/2026