pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: justin <justin@emproshunts.com>
To: Matthew Wakeling <matthew@flymine.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org
Subject: Re: plpgsql arrays
Date: Tue, 07 Apr 2009 11:45:00 -0400
Message-ID: <49DB74FC.9080705@emproshunts.com> (raw)
In-Reply-To: <alpine.DEB.2.00.0904071630420.791@aragorn.flymine.org>
References: <alpine.DEB.2.00.0904031420470.21772@aragorn.flymine.org>
	<28757.1238767715@sss.pgh.pa.us>
	<alpine.DEB.2.00.0904071616350.791@aragorn.flymine.org>
	<49DB700F.8020108@emproshunts.com>
	<alpine.DEB.2.00.0904071630420.791@aragorn.flymine.org>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Matthew Wakeling wrote:
<blockquote
 cite="mid:alpine.DEB.2.00.0904071630420.791@aragorn.flymine.org"
 type="cite">On Tue, 7 Apr 2009, justin wrote:
  <br>
  <blockquote type="cite">
    <blockquote type="cite">What would be the syntax for putting a
single row from a cursor into a variable? I have tried:
      <br>
      <br>
FETCH INTO left left_cursor;
      <br>
      <br>
which says syntax error, and
      <br>
      <br>
left = FETCH left_cursor;
      <br>
      <br>
which gives the error 'ERROR:&nbsp; missing datatype declaration at or near
"="'
      <br>
    </blockquote>
    <br>
Have to declare Left variable&nbsp; as record data type declaration part of
the function
    <br>
  </blockquote>
  <br>
It is.
  <br>
  <br>
CREATE OR REPLACE FUNCTION overlap_gene_primer() RETURNS SETOF RECORD
AS $$
  <br>
DECLARE
  <br>
&nbsp;&nbsp;&nbsp; left location;
  <br>
&nbsp;&nbsp;&nbsp; retval RECORD;
  <br>
BEGIN
  <br>
&nbsp;&nbsp;&nbsp; DECLARE left_cursor NO SCROLL CURSOR FOR SELECT location FROM
location, gene WHERE location.id = gene.id ORDER BY objectid, start,
end;
  <br>
&nbsp;&nbsp;&nbsp; left = FETCH left_cursor;
  <br>
END;
  <br>
$$ LANGUAGE plpgsql;
  <br>
  <br>
Matthew
  <br>
</blockquote>
<br>
Change the type to Record<br>
from the help file<br>
<code class="command">FETCH</code> retrieves the next row from the
cursor into a target, which might be a <b>row variable, a record
variable, or a comma-separated </b>list of simple variables, just like
<code class="command">SELECT INTO</code>. If there is no next row, the
target is set to NULL(s). As with <code class="command">SELECT INTO</code>,
the special variable <code class="literal">FOUND</code> can be checked
to see whether a row was obtained or not<br>
<br>
</body>
</html>



view thread (32+ messages)  latest in thread

Message-ID: <49DB74FC.9080705@emproshunts.com>
Permalink:  ../49DB74FC.9080705@emproshunts.com/
Also on:    postgresql.org/message-id/49DB74FC.9080705@emproshunts.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: justin@emproshunts.com, matthew@flymine.org, tgl@sss.pgh.pa.us
  Subject: Re: plpgsql arrays
  In-Reply-To: <49DB74FC.9080705@emproshunts.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox