From: | Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> |
---|---|
To: | Aland Laines <aland(dot)laines(at)gmail(dot)com> |
Cc: | Ayuda <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | Re: Crear Funciones en PG |
Date: | 2012-08-30 02:55:58 |
Message-ID: | 1346294912-sup-2984@alvh.no-ip.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
Excerpts from Aland Laines's message of lun ago 06 18:37:46 -0400 2012:
> 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;
En vez de hacer DROP SEQUENCE seguido por CREATE SEQUENCE, es mucho más
sensato hacer ALTER SEQUENCE (o llamar la función setval()) para cambiar
el próximo valor de la secuencia. Mira
http://stackoverflow.com/a/5943183
(La función que publiqué ahí es muy útil si una secuencia está siendo
usada en más de una tabla, que fue un problema que tuvimos con un
cliente).
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
From | Date | Subject | |
---|---|---|---|
Next Message | Hellmuth Vargas | 2012-08-30 05:53:01 | Re: [pgsql-es-ayuda] consulta para ver las tablas, indices,etc que están involucrados en un lock |
Previous Message | Guillermo Villanueva | 2012-08-30 02:39:29 | Re: Crear Funciones en PG |