The answer below is outdated now, as PostgreSQL v11 has introduced support for proper stored procedures. The method proc can now only call a stored procedure using the new CALL
syntax.
How should void functions be handled with pg-promise in the most appropriate manner?
Utilize the proc Database method.
db.proc('proc_name', [param1, param2,...])
.then(data => {
/* data could be null or an object */
})
.catch(error => {
/* error handling */
});
UPDATE
When using proc
, how can parameter types be specified to resolve errors like
function foo(unknown) does not exist
? For example, if I try db.proc('foo($1::int2[])', x)
, it gives a syntax error at or near "("
.
You cannot specify parameter types with the proc method, which is designed for simplicity. If your call requires SQL type casting, you should execute it as a regular query with casting inside the template:
db.oneOrNone('SELECT * FROM proc_name($1::int2[], $2, ...)', [param1, param2,...])
.then(data => {
/* data may be null or an object */
})
.catch(error => {
/* handle any errors */
});
In this context, the oneOrNone method provides similar result expectations as the proc method.