Matthew Wakeling wrote:
On Tue, 7 Apr 2009, justin wrote:
What would be the syntax for putting a
single row from a cursor into a variable? I have tried:
FETCH INTO left left_cursor;
which says syntax error, and
left = FETCH left_cursor;
which gives the error 'ERROR: missing datatype declaration at or near
"="'
Have to declare Left variable as record data type declaration part of
the function
It is.
CREATE OR REPLACE FUNCTION overlap_gene_primer() RETURNS SETOF RECORD
AS $$
DECLARE
left location;
retval RECORD;
BEGIN
DECLARE left_cursor NO SCROLL CURSOR FOR SELECT location FROM
location, gene WHERE location.id = gene.id ORDER BY objectid, start,
end;
left = FETCH left_cursor;
END;
$$ LANGUAGE plpgsql;
Matthew
Change the type to Record
from the help file
FETCH retrieves the next row from the
cursor into a target, which might be a row variable, a record
variable, or a comma-separated list of simple variables, just like
SELECT INTO . If there is no next row, the
target is set to NULL(s). As with SELECT INTO ,
the special variable FOUND can be checked
to see whether a row was obtained or not
|