0

I am new with plpgsql. I create new function

CREATE OR REPLACE FUNCTION createObj(number integer)
RETURNS INTEGER AS
$$
BEGIN

END;
$$

I have problem that if I want to make query in the body of the function and use in the query the the number variable while in the table their is a number the boolean is always true.

something like:

 Select * from objects O, where O.number=number...

so number is not the number of the function but the filed in the table. Their is a way to implement this and dont change the variable name?

1 Answer 1

1

Define your parameters with a prefix to distinguish them from columns:

CREATE OR REPLACE FUNCTION createObj(in_number integer)
RETURNS INTEGER AS
$$
BEGIN
    Select * from
    objects O
    where O.number = in_number...
END;

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

2 Comments

thanks, I though that their is a way to take the original variable.. Thanks anyway .
@Alon . . . You can use $1. I think it is just a good habit to use parameter and variable names that can't be confused with other things.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.