Skip to content

INSERT ERROR error: invalid message format #3353

Closed as not planned
Closed as not planned
@fukemy

Description

@fukemy

Hi, I have table like this:

CREATE TABLE IF NOT EXISTS ${tableName} (
        id BIGSERIAL PRIMARY KEY NOT NULL,
        value text,
        uploaded boolean DEFAULT false
      )

I get the data from datalogger like this:
"2024-12-20 13:37:23.400",4783.83,5375.243,6897.802,4267.536,4205.374,12072.36,5279.975,7320.997,20.99808,20.53375,-112.3837,-112.5886,-106.6176,-106.4814,-106.4782,-106.6504
I removed the " then use INSERT:

const data = msg.toString().replaceAll("\"", "")
            const tableName = datalogger.datalogger_name + '___' + device.Serial
            const query = `
                INSERT INTO ${tableName}(value)
                VALUES('${data}')
            `
            if(pgClient._connected ){
                pgClient.query(query)
                .then(() => { console.log('added data to ' + tableName) })
                .catch(error => {
                    console.log('added data to ' + tableName + ' failed: ', error, query)
                })
            }

But I got error:

error: invalid message format
    at C:\Users\vedax\Desktop\robot\cr1000\node_modules\pg\lib\client.js:535:17
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
  length: 81,
  severity: 'ERROR',
  code: '08P01',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'pqformat.c',
  line: '640',
  routine: 'pq_getmsgend'
}
                INSERT INTO CR1000X_1___2748(value)
                VALUES('2024-12-20 13:37:23.450,4783.923,5375.324,6897.892,4267.62,4205.655,12072.45,5280.143,7321.269,20.99808,20.53375,-112.3837,-112.5886,-106.6176,-106.4814,-106.4782,-106.6504        
')

Can you point me what am I wrong? Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions