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 8B757D1B19B; Wed, 14 Jul 2004 12:30:05 -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 85135-07; Wed, 14 Jul 2004 15:29:57 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 8FD35D1B199; Wed, 14 Jul 2004 12:29:56 -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 i6EFTui7075372; Wed, 14 Jul 2004 15:29:56 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i6EFDpxq068618; Wed, 14 Jul 2004 15:13:51 GMT From: mmarencibia@yahoo.es (Marcos Medina) X-Newsgroups: comp.databases.postgresql.novice, comp.databases.postgresql.sql, comp.databases.postgresql.general Subject: FOR-IN-EXECUTE, why fail? Date: 14 Jul 2004 08:13:40 -0700 Organization: http://groups.google.com Lines: 38 Message-ID: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: groups-abuse@google.com 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.3 tagged_above=0.0 required=5.0 tests=UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200407/562 X-Sequence-Number: 63161 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? Tahnks....