Mirá, donde dice:
maximo =(select max("IdeReg") from "Publicacion")::integer;
if(maximo is null) then
maximo=0;
end if;Yo lo harías así: select coalesce(max(IdeReg),0) into maximo from Publicacion Y donde dice: maximo=maximo+1; reemplazalo por maximo := maximo + 1; Y quizá sería bueno también hacer lo que te dice Aland Guillermo Villanueva 2012/8/20 Aland Laines <[email protected]> > en el ejemplo que puse como seria eso Guillermo? > > Gracias; > > *Aland Laines Calonge* > Twitter: @lainessolutions > http://about.me/aland.laines > > > > > 2012/8/20 Guillermo Villanueva <[email protected]> > >> La asignación en plpgsql es con := >> Guillermo Villanueva >> >> >> >> >> 2012/8/6 Aland Laines <[email protected]> >> >>> >>> 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 >>> >>> >>> >> >
