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?

asked Nov 25, 2015 at 2:09

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;
$$
answered Nov 25, 2015 at 2:18
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

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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