1

I have created a simple nodeJS script and wanted to insert a few records to Postgres DB, how do I execute a Postgres function from NodeJS script.

1 Answer 1

2

Using pg-promise, you can try this:

await db.func('funcName', ['arg1','arg2']);

Another way:

await db.any('select * from funcName($1, $2)', [arg1,'arg2']);

And for stored procedures:

await db.proc('procName', ['arg1','arg2']);

See API: func and proc.

Sign up to request clarification or add additional context in comments.

Comments

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.