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?
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?
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:
select * from mydata, i've got the error relation "mydata" does not exist. Can ou help me in this matter?