Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proc to return a row of OUT values #692

Closed
papawou opened this issue Jan 10, 2020 · 5 comments
Closed

Proc to return a row of OUT values #692

papawou opened this issue Jan 10, 2020 · 5 comments

Comments

@papawou
Copy link

papawou commented Jan 10, 2020

In postgresql documentation:

The mode of an argument: IN, INOUT, or VARIADIC. If omitted, the default is IN. (OUT arguments are currently not supported for procedures. Use INOUT instead.)

Procedures are considered like functions who returns nothing but postgresql let you returns something.

And pg-promise use by default querymask 'none' when using proc.

Why ?

@vitaly-t
Copy link
Owner

vitaly-t commented Jan 10, 2020

I'm not sure if output variables are at all supported by the driver here. If they are, then please provide a complete example, using a generic query for such a procedure.

@papawou
Copy link
Author

papawou commented Jan 10, 2020

Sorry, i'm not good english speaker and don't understand well what you are asking.

Here is an example:

CREATE OR REPLACE PROCEDURE test(INOUT output_value boolean)
LANGUAGE plpgsql AS $$
BEGIN
    output_value := true;
END;$$;

It's INOUT argument we must give a value this is why the null value in pg-promise functions parameters.

for preventing that we can set a default value in procedure definition
CREATE OR REPLACE PROCEDURE test(INOUT output_value boolean DEFAULT null)

db.proc("test", [ null ]) throw an error because query return a row.

QueryResultError {
    code: queryResultErrorCode.notEmpty
    message: "No return data was expected."
    received: 1
    query: "call test(null)"
}

Following the documentation, it's normal behavior, proc use
none('CALL $1:alias($2:csv)', [procName, values])

For getting procedure working with INOUT arguments we need change querymask to accept at least one row retrieved
db.oneOrNone('CALL $1:alias($2:csv)', ["test", [ null ]]) return { output_value: true }

pg-promise seems to handle INOUT arguments (OUT currently not supported by postgresql).

sorry again for my english 🥖

@vitaly-t
Copy link
Owner

Ok, if the procedure can return one row like that, then the API will need to be revised.

@vitaly-t vitaly-t changed the title Why using querymask 'none' for proc() when procedure can return value with INOUT ? Proc to return a row with OUT values Jan 11, 2020
@vitaly-t vitaly-t changed the title Proc to return a row with OUT values Proc to return a row of OUT values Jan 11, 2020
vitaly-t added a commit that referenced this issue Jan 11, 2020
@vitaly-t
Copy link
Owner

Updated functionality with this commit.

@vitaly-t
Copy link
Owner

vitaly-t commented Jan 11, 2020

The update has been released in v10.3.3.

@MendesKevin Give it a go, and let me know ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants