clickhouse icon indicating copy to clipboard operation
clickhouse copied to clipboard

Can not insert with value = null

Open phuc49 opened this issue 1 year ago • 2 comments

static mapRowAsObject(fieldList, row) {
	return fieldList
		.map(f => {
			return encodeValue(false, row[f] != null ? row[f] : '', 'TabSeparated');
		})
		.join('\t');
}

if value = null why dont insert that null value to db

phuc49 avatar Nov 17 '23 07:11 phuc49

Maybe try inserting it as a 'NULL' string? Here's a simplified approach on how I did it in my app:

const dto = (
  psid: string,
  // ....
): Array<string | number> => {
  return [
    psid,
    ....
  ]

// call it like
dto(params.psid)

// or
dto('NULL')
}

then you can save it like:

const query = `INSERT INTO table (*) VALUES ${_join(data, ',')}`
      try {
        await clickhouse.query(query).toPromise()
      } catch (e) {
        console.error(`[CRON WORKER] Error whilst saving log data: ${e}`)
      }

Blaumaus avatar Dec 16 '23 20:12 Blaumaus

and eventually it should store the data as null: Screenshot 2023-12-16 at 20 50 34

Blaumaus avatar Dec 16 '23 20:12 Blaumaus