1
我有要插入到一個postgres分貝大型數據集的多個插入,我能實現這個使用PG-承諾這樣與PG-承諾加法數據
function batchUpload (req, res, next) {
var data = req.body.data;
var cs = pgp.helpers.ColumnSet(['firstname', 'lastname', 'email'], { table: 'customer' });
var query = pgp.helpers.insert(data, cs);
db.none(query)
.then(data => {
// success;
})
.catch(error => {
// error;
return next(error);
});
}
該數據集是陣列對象是這樣的:
[
{
firstname : 'Lola',
lastname : 'Solo',
email: '[email protected]',
},
{
firstname : 'hello',
lastname : 'world',
email: '[email protected]',
},
{
firstname : 'mami',
lastname : 'water',
email: '[email protected]',
}
]
的挑戰是我所不包括的數據集,並不能null
列added_at
。如何爲查詢的每個記錄插入添加一個時間戳。
運行'alter table customer alter column added_at set default now();'或db上類似的設置列的默認值 –
@VaoTsun感謝您的洞察。 –