0

When trying to return table in postgres, this my query:

CREATE OR REPLACE FUNCTION list_log_approval(IN p_create_code INTEGER,IN p_update_code INTEGER) RETURNS
TABLE(processcode integer, processname VARCHAR,id BIGINT, pleader CHARACTER VARYING,activity VARCHAR,date_plead timestamp)
LANGUAGE plpgsql AS $$ 
BEGIN
        IF NOT EXISTS( SELECT * FROM log_approval WHERE processcode = $1 and status = 'A' or status = 'D')AND NOT EXISTS(SELECT * FROM log_approval WHERE processcode = $2 and status = 'A' or status = 'D') THEN
                RETURN QUERY SELECT * from vw_list_appv;
        END IF;
    RETURN;
END $$;

-- i call like this

select * from list_log_approval(1070,1072)

I get the following error:

[Err] ERROR: column reference "processcode" is ambiguous
LINE 3: processcode**

why is it ambiguous?

1 Answer 1

1

processcode is used both as function parameter and as table column.

The best thing is to use function parameters with a different name, like p_processcode.

But you can also disambiguate by qualifying the name: log_approval.processcode for the column and list_log_approval.processcode for the function parameter.

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.