0

I am trying to workout how to call a postgres function using node-postgres but unfortunately cannot find any examples.

I am seeing examples on the web like this but this is based off a different package (pg-promise), which I am not using:

db.func('inserttask', ['task_name','task_type'])

I am also seeing examples like this as well:

const query= `SELECT inserttask($1, $2)`;        
result= await pool.query(query, ['task_name','task_type']);

I haven't as yet tried these as I wanted to check which approach is correct, when using node-postgres.

1 Answer 1

1

From the link you provided:

const res = await client.query('SELECT $1::text as message', ['Hello world!'])

Isn't it good enough?

If you have official docs that answer your question, it is usually the one to trust.

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

2 Comments

Is this actually for a function call?
I don't think there is any difference, just try.

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.