Re: FOR ... IN

From: William Leite Araújo <william(dot)bh(at)gmail(dot)com>
To: "Alain Roger" <raf(dot)news(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: FOR ... IN
Date: 2006-11-07 10:29:07
Message-ID: bc63ad820611070229v59286d05n7db70c7039262a93@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2006/11/6, Alain Roger <raf(dot)news(at)gmail(dot)com>:
>
> Hi,
>
> Before (in version 8.0.1), i did the following thing and it was working
> well...now (in version 8.1.4) it seems that it does not work anymore...
> problem is with FOR rec IN loop...
> So how can i tell "FOR all RECORDS from select * from articles,
> articletypes, department where ..." LOOP ... ?
>
> thanks,
> Al.
>
>
> CREATE OR REPLACE FUNCTION "public"."SP_U_001" ("TypeOfArticle" varchar)
> RETURNS SETOF "public"."active_articles" AS
> $body$
> DECLARE
> TypeArt VARCHAR := $1;
> rec RECORD;
> res active_articles;
> /**************************************/
> BEGIN
>
> FOR rec IN
> select *
> from articles, articletypes, department
> where
> articletypes.articletype_type = $1
> AND articles.articletype_id = articletypes.articletype_id
> AND articles.department_id = department.department_id
> AND articles.validity_period_end > now()
> LOOP
> res.article_type := rec.articletypes.articletype_type;
> res.article_author := rec.articles.author;
> res.department_owner := rec.department.department_name;
> res.department_picture := rec.department.department_picture;
> res.article_title := rec.articles.title;
> res.article_content := rec.articles.content;
> res.date_creation := rec.articles.creation_date;
> res.date_start := rec.articles.validity_period_start;
> res.date_end := rec.articles.validity_period_end;
> RETURN NEXT res;
> END LOOP;

RETURN;

END;
> $body$
> LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

Never forgot of return before "END" procedure;

--
William Leite Araújo

In response to

  • FOR ... IN at 2006-11-06 19:39:21 from Alain Roger

Responses

Browse pgsql-general by date

  From Date Subject
Next Message redhog 2006-11-07 11:57:43 X.50x OID representation
Previous Message Tomasz Ostrowski 2006-11-07 10:24:25 Re: Dump all databases to corresponding files