0

I am trying insert random data(size must be 250K) to the table. here is my table schema DDL: CREATE TABLE entries (entryID serial PRIMARY KEY NOT NULL,content bytea);

Here is my code:

'use strict';

var pg  = require('pg');
var randomBytes = require('randombytes');

var pool = new pg.Pool({
 host     : 'xxx',
 user     : 'postgres',
 password : 'xxxx',
 database : 'mydb',
 max:20,
 idleTimeoutMillis: 3000,
});

async function run(){

 for (let i=0; i<100000; i++){

 await new Promise(done => setTimeout(done, 100));
 await pool.connect(function (error, connection) {
   if (error) throw error;
   connection.query('insert into entries(content) values($1)', [randomBytes(8)+Buffer.alloc(249992,1)], function (error, results, fields) {
     if (error) throw error;
     connection.release();
     console.log("Current row "+ i + "!");
   });
 });
}
}
run();

everytime i run the code , after server rounds, it errored as infor : error: invalid byte sequence for encoding "UTF8": 0x00 or error: invalid input syntax for type bytea

here is the env info: psql (13.11 (Debian 13.11-0+deb11u1), server 14.7) SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)

i run the similar code in mysql(with mediumblob ) is fine. how can i run it in postgresql

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.