8

I am using "pg" module to handle with postgresql db ,what how to call function using pg i have doubt,

I am calling function using query method,

client.query("SELECT * FROM SQSP_IsUserNameExists($1)",[userName], function(err, result) {
  // some code.

});

that is working fine, but is this right way to call postgresql functions.

1
  • How is the structure for your stored procedure? Commented Sep 27, 2016 at 14:51

2 Answers 2

8

Your code looks correct.

But if you want a nicer syntax, example with pg-promise:

// calling a function:
const result = await db.func('funcName', [userName]);
//=> SELECT * FROM funcName('user-name')

// calling a stored procedure:
const result = await db.proc('procName', [userName]);
//=> CALL procName('user-name')
Sign up to request clarification or add additional context in comments.

Comments

-1

From the PostgrSQL side, if the function returns a result set than yes the SQL is syntax is correct. As for the Node call syntax I am not familiar with that framework. But if its returning results then I say task complete.

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.