X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 333A39DCC7A for ; Thu, 16 Mar 2006 11:49:09 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 34204-02-4 for ; Thu, 16 Mar 2006 11:49:13 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from relay01.mdc.ubisoft.com (relay01.mdc.ubisoft.com [216.98.56.134]) by postgresql.org (Postfix) with ESMTP id 785E79DCC8A for ; Thu, 16 Mar 2006 11:49:06 -0400 (AST) Received: from mdc-owa01.ubisoft.org (srvowa1-mdc.ubisoft.org [10.129.1.20]) by smarthost.mdc.ubisoft.com (Postfix) with ESMTP id EBBA94BC2B; Thu, 16 Mar 2006 10:49:10 -0500 (EST) Received: from UBIMAIL1.ubisoft.org ([10.129.1.15]) by mdc-owa01.ubisoft.org with Microsoft SMTPSVC(6.0.3790.1830); Thu, 16 Mar 2006 10:49:10 -0500 x-mimeole: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Re: help with function Date: Thu, 16 Mar 2006 10:49:10 -0500 Message-ID: <1E293D3FF63A3740B10AD5AAD88535D201CAB61B@UBIMAIL1.ubisoft.org> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [SQL] help with function Thread-Index: AcZJECQTU54YDxkwTlOV6S3ofXF69AAAMGDg From: "Daniel Caune" To: "lacou" , X-OriginalArrivalTime: 16 Mar 2006 15:49:10.0711 (UTC) FILETIME=[2ABF9C70:01C64911] X-Ubisoft-MailScanner-Information: Please contact administrators@ubisoft.qc.ca X-Ubisoft-MailScanner: Found to be clean X-Ubisoft-MailScanner-SpamCheck: X-MailScanner-From: daniel.caune@ubisoft.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.116 required=5 tests=[AWL=0.116] X-Spam-Score: 0.116 X-Spam-Level: X-Archive-Number: 200603/233 X-Sequence-Number: 24579 > Hello, >=20 > I have 2 tables where each table has a column named "comments" and the > tables are related as a one to many. I want to concatenate all the > comments of the many side to the one side so I wrote the following > plpgsql function to do so. >=20 >
> CREATE OR REPLACE FUNCTION fixcomments()
>    RETURNS int4 AS
> $BODY$
> DECLARE
>      mviews RECORD;
>      i int4;
> BEGIN
>=20
>      FOR mviews IN SELECT * FROM saleorder WHERE comments is not null
> and comments <> '' LOOP
>=20
>          -- Now "mviews" has one record from saleorder
>=20
>          EXECUTE 'UPDATE sale SET comments =3D ' ||
> quote_ident(sale.comments) || quote_ident(mviews.comments)
> 		|| ' WHERE sale.id =3D ' || quote_ident(mviews.sale_id);

EXECUTE 'UPDATE sale SET comments =3D ''' || quote_ident(sale.comments =
||
mviews.comment) || ''' WHERE sale.id =3D ''' ||
quote_ident(mviews.sale_id) || '''';

Does that help?


>      i :=3D i + 1;
>      END LOOP;
>=20
>      RETURN i;
> END;
> $BODY$
>    LANGUAGE 'plpgsql' VOLATILE;
>=20
> 
>=20 > I have the following error when I run this code: >=20 >
> ERROR:  missing FROM-clause entry for table "sale"
> CONTEXT:  SQL statement "SELECT  'UPDATE sale SET comments =3D ' ||
> quote_ident(sale.comments) || quote_ident( $1 ) || ' WHERE sale.id =3D =
'
> || quote_ident( $2 )"
> PL/pgSQL function "fixcomments" line 11 at execute statement
> 
>=20 > Doesn anybody know what I am doing wrong here ? >=20 > Lacou. >=20 >=20 > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend