A single row can be inserted like this:
client.query("insert into tableName (name, email) values ($1, $2) ", ['john', 'john@gmail.com'], callBack)
This approach automatically comments out any special characters.
How do i insert multiple rows at once?
I need to implement this:
"insert into tableName (name, email) values ('john', 'john@gmail.com'), ('jane', 'jane@gmail.com')"
I can just use js string operators to compile such rows manually, but then i need to add special characters escape somehow.
doesn't help? Futher more, you can manually generate a string for query:
if you read here, https://github.com/brianc/node-postgres/issues/530 , you can see the same implementation.
Following this article: Performance Boost from pg-promise library, and its suggested approach:
An example of using it, exactly as in your case:
And it will work with an array of objects as well:
UPDATE
For a high-performance approach via a single
INSERT
query see Multi-row insert with pg-promise.One other way using PostgreSQL json functions: