| From: | Anthony <asotolongo(at)uci(dot)cu> | 
|---|---|
| To: | Aland Laines <aland(dot)laines(at)gmail(dot)com> | 
| Cc: | pgsql-es-ayuda(at)postgresql(dot)org | 
| Subject: | Re: Crear Funciones en PG | 
| Date: | 2012-08-06 22:54:08 | 
| Message-ID: | 50204B10.5080805@uci.cu | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-es-ayuda | 
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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Jorge Castellanos | 2012-08-06 23:02:30 | Re: Auto incrementar con Serial | 
| Previous Message | Aland Laines | 2012-08-06 22:37:46 | Crear Funciones en PG |