El 06/08/2012 18:37, Aland Laines escribió:
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
Hola al parecer no te permite ejecutar una sentencia con parametros,
bueno mira empaca todo lo de "SEQUENCE" en un texto y luego ejecuta eso con
execute tutexto;
algo mas o menos asi
tutexto:='
CREATE SEQUENCE "Publicacion_IdeReg_seq"
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
* START ' || maximo::text || '
*
CACHE 1';
execute tutexto;
saludos
10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS
INFORMATICAS...
CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION
http://www.uci.cu
http://www.facebook.com/universidad.uci
http://www.flickr.com/photos/universidad_uci