0

I want to store the value of this query inside a Stored Procedure:

select * from myname;

using

select * into mydata from myname

but an error "mydata" is not a known variable occurs. Is there a way to store those results into a variable in postgre?

2
  • it's an sql inside a stored procedure. Commented Aug 1, 2014 at 6:36
  • Then you need to show us the full code. Commented Aug 1, 2014 at 6:46

1 Answer 1

1

Assuming you are trying to do this in the context of a PL/PgSQL function, then you have to declare the variable first.

CREATE OR REPLACE FUNCTION foobar() RETURNS void AS $$
DECLARE
    mydata RECORD;
BEGIN
    SELECT * INTO mydata FROM mytable;
    -- now do something with mydata
END
$$ LANGUAGE plpgsql;

See:

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

5 Comments

thank you...but i cant use mydata for a query like this one : select * from mydata, i've got the error relation "mydata" does not exist. Can ou help me in this matter?
You will need to explain better what you are trying to do. Are you trying to select from the variable? Or select from a table named by the variable?
Im trying to select from the variable.
Afaik you cannot select from a variable. Maybe you had better open a new question describing what you are trying to achieve at a higher level
thanks @harmic im a beginner when it comes to stored procedure.

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.