Re: plpgsql and for with integer loopvar error

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Ari Kahn <akahn1(at)gmu(dot)edu>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: plpgsql and for with integer loopvar error
Date: 2005-01-17 19:38:55
Message-ID: 20050117113239.I13804@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Sat, 15 Jan 2005, Ari Kahn wrote:

> CREATE FUNCTION gets_nooky() returns numeric AS
> '
> DECLARE
> i integer;
> gt1cnt record;
> gt1 record;
> cluster record;
> cluster_cnt integer;
> slocus integer;
> minmax record;
>
> BEGIN
> SELECT INTO gt1 * FROM cgt1;
> SELECT count(*) INTO gt1cnt FROM cgt1;
>
> FOR i IN 1 .. SELECT count(*) FROM cgt1

I think either of
(SELECT count(*) FROM cgt1)
or
count(*) from cgt1
should work in practice (I personally like the former because that's the
scalar subquery syntax), however, since you're getting the count into
gt1cnt, why not just use the variable?

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message zeus 2005-01-17 23:31:40 "How do I ..." SQL question
Previous Message Yudie 2005-01-17 19:30:03 Re: query configuration for validate empty quote to zero