X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4B2F2D8614; Tue, 30 Aug 2005 13:50:24 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 05110-09; Tue, 30 Aug 2005 16:50:20 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 89CB4D85DE; Tue, 30 Aug 2005 13:50:17 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j7UGoEq7024880 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 30 Aug 2005 10:50:17 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j7UGoE4A064975; Tue, 30 Aug 2005 10:50:14 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j7UGoEJD064974; Tue, 30 Aug 2005 10:50:14 -0600 (MDT) (envelope-from mfuhr) Date: Tue, 30 Aug 2005 10:50:14 -0600 From: Michael Fuhr To: Postgres Admin Cc: pgsql-sql@postgresql.org, PostgreSQL - Admin Subject: Re: plpgsql question Message-ID: <20050830165013.GA57465@winnie.fuhr.org> References: <1C7C5DE3-5EB5-4EB8-A187-290EF5081BD7@sitening.com> <4314863A.3030107@productivitymedia.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4314863A.3030107@productivitymedia.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 required=5 tests=[AWL=0.005] X-Spam-Level: X-Archive-Number: 200508/387 X-Sequence-Number: 18706 On Tue, Aug 30, 2005 at 12:15:54PM -0400, Postgres Admin wrote: > > Can I do something like this: It's good that you gave an example, but it would also be good to give a summary of what you're trying to do and what trouble you're having so people don't have to guess. > CREATE TABLE sample (id SERIAL, node INTEGER, parent INTEGER); > INSERT INTO sample(node,parent) VALUES(1,0); > INSERT INTO sample(node,parent) VALUES(2,0); > INSERT INTO sample(node,parent) VALUES(3,1); > INSERT INTO sample(node,parent) VALUES(4,3) > > CREATE OR REPLACE FUNCTION article_display(anyelement, anyelement) > RETURNS SETOF samle AS $$ I assume you want to return "SETOF sample", not "samle". When posting code please post the actual code you're running so typos don't distract from the real problem (unless a typo *is* part of the problem). > DECLARE > articleRow sample%ROWTYPE; > BEGIN > FOR articleRow IN SELECT comments > FROM theirry.articles You're selecting a column of one table (theirry.articles) into a row type variable of another table (sample). If the value of comments can't be converted to an integer (the type of sample's first column) then you'll get a syntax error. And what about the other columns of sample? What are you really trying to do here? > ORDER BY article_id > DESC LIMIT $1 > OFFSET $2 LOOP If you're using the function's arguments like this, why did you declare them as anyelement instead of integer? > RETURN NEXT articleRow; > END LOOP; > RETURN; > END; > $$ LANGUAGE plpgsql; It's not clear what you're trying to do nor what problems you're having. Is this example real or a contrived facsimile of what you're really trying to do? Could you provide some more information? -- Michael Fuhr