X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 69C83D1B440; Wed, 21 Jul 2004 00:15:52 -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 73044-02; Wed, 21 Jul 2004 03:15:47 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id BC547D1B3A4; Wed, 21 Jul 2004 00:15:43 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i6L3FRr9068237; Wed, 21 Jul 2004 03:15:43 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i6L2lGVZ058662; Wed, 21 Jul 2004 02:47:16 GMT From: Gaetano Mendola X-Newsgroups: comp.databases.postgresql.novice, comp.databases.postgresql.sql, comp.databases.postgresql.general Subject: Re: FOR-IN-EXECUTE, why fail? Date: Sat, 17 Jul 2004 11:49:08 +0200 Organization: PYRENET Midi-pyrenees Provider Lines: 52 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@pyrenet.fr User-Agent: Mozilla Thunderbird 0.7.1 (Windows/20040626) X-Accept-Language: en-us, en In-Reply-To: X-Enigmail-Version: 0.84.2.0 X-Enigmail-Supports: pgp-inline, pgp-mime To: "pgsql-general@postgresql.org.pgsql-novice@postgresql.org.pgsql-sql"@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/626 X-Sequence-Number: 63225 Marcos Medina wrote: > I wrote the following: > CREATE OR REPLACE FUNCTION escritorio.seq_valor_actual( text) > RETURNS integer AS ' > DECLARE > secuencia ALIAS FOR $1; > valor_actual integer := 0; > v_query text; > actual integer; > BEGIN > RAISE NOTICE ''el parametro tiene el siguiente valor %'' ,secuencia; > > v_query := ''SELECT last_value FROM '' || quote_ident(secuencia); > RAISE NOTICE ''la sentencia a ejecutar es %'' ,v_query; > > FOR actual IN EXECUTE v_query LOOP > valor_actual := actual; > END LOOP; > > RETURN valor_actual; > > END; > 'LANGUAGE 'plpgsql'; > > And i call: > select seq_valor_actual('s_id_reserva'); > > > The s_id_reserva is a sequence. The error is the following: > WARNING: plpgsql: ERROR during compile of seq_valor_actual near line 12 > ERROR: missing .. at end of SQL expression > > I think the problem is in the FOR but i see correct all. > > Can i help me? > > Any idea? You shall declare actual as RECORD and perform inside the loop: valor_actual = actual.last_value; Regards Gaetano Mendola