Crear Funciones en PG

From: Aland Laines <aland(dot)laines(at)gmail(dot)com>
To: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Crear Funciones en PG
Date: 2012-08-06 22:37:46
Message-ID: CABk_u6SDfbL71p=fw1+wgxkzOXf6xV-6RVkKTVRh5xs3ObQEaA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Hola a todos, hace poco que estoy usando postgres.

Estoy viendo lo de funciones y quise crear esta:

----------------------------
CREATE OR REPLACE FUNCTION adecuar_publicacion() RETURNS boolean as $BODY$
DECLARE
maximo integer;
BEGIN
maximo =(select max("IdeReg") from "Publicacion")::integer;
if(maximo is null) then
maximo=0;
end if;
maximo=maximo+1;
DROP SEQUENCE "Publicacion_IdeReg_seq";
CREATE SEQUENCE "Publicacion_IdeReg_seq"
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
* START maximo*
CACHE 1;
ALTER TABLE "Publicacion_IdeReg_seq"
OWNER TO postgres;
ALTER TABLE "Publicacion" ADD CONSTRAINT "IdeReg" PRIMARY KEY("IdeReg" );
ALTER TABLE "Publicacion" alter column "IdeReg" set default
nextval('"Publicacion_IdeReg_seq"'::regclass);
UPDATE "Publicacion" set "ANULADO" = null WHERE "ANULADO" = '';
UPDATE "Publicacion" set "NroCar" = null WHERE "NroCar" = '';
UPDATE "Publicacion" set genero = null WHERE genero = '';
if found then
return true;
else
return false;
end if;
END;
$BODY$
LANGUAGE 'plpgsql';
-------------------------------------------------------

El problema esta en la linea *START maximo* me dice que tengo un error de
sintaxis, quiero saber como pasarle el valor de la variable *maximo* para
que no me arroje error de sintaxis, gracias por su ayuda.

*Aland Laines Calonge*
Twitter: @lainessolutions
http://about.me/aland.laines

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Anthony 2012-08-06 22:54:08 Re: Crear Funciones en PG
Previous Message Fabio Arias 2012-08-06 22:27:43 INSERT LENTOS EN CAMPOS TEXT / BYTEA