Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INSERT ERROR error: invalid message format #3353

Closed
fukemy opened this issue Dec 20, 2024 · 1 comment
Closed

INSERT ERROR error: invalid message format #3353

fukemy opened this issue Dec 20, 2024 · 1 comment
Labels

Comments

@fukemy
Copy link

fukemy commented Dec 20, 2024

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

@charmander
Copy link
Collaborator

Seems to have been also posted at https://stackoverflow.com/questions/79296861/postgres-insert-error-error-invalid-message-format, so I won’t duplicate work. Check for NUL, use parameters, don’t read the private _connected field.

@charmander charmander closed this as not planned Won't fix, can't repro, duplicate, stale Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants