PostgreSQL COPY格式.csv文件,最多只能复制1000行

时间:2019-12-22 01:23:21

标签: javascript node.js postgresql pg-promise node-postgres

我是PostgreSQL的新手。我正在生成.csv文件,然后使用PostgreSQL COPY,以便将数据导入到Table中。我面临的问题是,.csv文件将填充我想要的确切数据量,但是COPY将仅插入其中的一部分。日志中没有错误,所以我不太确定问题出在哪里。请指教。我的代码看起来像这样。
我的查询就是这个:

const faker = require('faker');
const Promise = require('bluebird');
const db = require('./queries.js');
const fs = require('fs');
const csv = require('fast-csv');
const ws = fs.createWriteStream('test.csv')


function users() {
   var result = [];
    for (let i = 1; i <= 10000; i ++) {

        var final = [];
        let randomName = faker.name.firstName();
        randomName.includes("'") ? randomName = randomName.split("'").slice(1).join('') : randomName;
        const budget = faker.random.number({min: 1000, max: 10000});
        const age = faker.random.number({min: 21, max: 70});
        const phone = faker.random.number({min: 1000000000, max: 9999999999}).toString();
        let street = faker.address.streetAddress().split(' ').splice(1, 2).toString();
        street.includes(",") ? street = street.split(",").slice(1).join('') : street;
        const zip = faker.random.number({min: 10000, max: 99999});

        final.push(randomName, age, phone, street, zip, budget);
        result.push(final); 
    }
    csv.write(result).pipe(ws);
    db.insert();

}

var promise = require('bluebird');
var options = {
  // Initialization Options
  promiseLib: promise
};

var pgp = require('pg-promise')(options);
var connectionString = 'postgres://localhost:5432/sdc';
var db = pgp(connectionString);
db.any("COPY customer( user_name, user_age, user_phone, street, zip, budget) FROM 'absolute path' DELIMITER ',' CSV HEADER;")

First Second Third

0 个答案:

没有答案