No será mejor hacer un contraint para evitar duplicados?

algo como:

add constraint PK_ALUMNOS primary key (dni)

Luego la aplicación debería de evaluar si se generó el error por lave
primaria.


2008/11/12 Roberto A. <gedeon56@gmail.com>
Roberto Almanza LL.

Hola a todos los de la lista el problema que tengo es el siguiente:


CREATE TABLE ALUMNO( dni varchar(15) primary key,
nombre var_nomb,
ap_pat var_nomb,
ap_mat var_nomb,
telf varchar(12),
calle varchar(50),
ciudad varchar(50),
provincia varchar(50),
fecha_nac date not null,
estado_civil char(1) default 'S' check(estado_civil
in('S','C','V','P','D'))
);


-------------------------------------------------trigger---------------------------------------------------------------

CREATE TRIGGER VERIFICAR_ALUMNO

BEFORE INSERT ON ALUMNO

FOR EACH ROW EXECUTE PROCEDURE Validar_Alumno();



CREATE OR REPLACE FUNCTION Validar_Alumno()

RETURNS TRIGGER AS

$$

BEGIN

if( not exists(select * from alumno where dni=new.dni))then

insert into alumno values(new.*);

else

RAISE EXCEPTION 'Ya existe un usuario registrado con este dni';

end if;

return null;

END;

$$

LANGUAGE 'PLPGSQL';


-------------------------------------------------trigger---------------------------------------------------------------



el problema surge cuando quiero insertar datos en esta table

insert into alumno values('7.777.777-L','Jose
Antonio','Arenas','Bernabé','96-568-47-24','Pza. La paz, 3',
'Altea','Alicante','25-05-1973','C');

Y me genera este error . si alguien podria desirme por que para esto.

ERROR: stack depth limit exceeded
HINT: Increase the configuration parameter "max_stack_depth", after
ensuring the platform's stack depth limit is adequate.
CONTEXT: SQL statement "SELECT ( not exists(select * from alumno where
dni= $1 ))"
PL/pgSQL function "val_alumno" line 2 at IF
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"
PL/pgSQL function "val_alumno" line 3 at SQL statement
SQL statement "INSERT INTO alumno VALUES ( $1 .*)"




Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 3 | next ›
Discussion Overview
grouppgsql-es-ayuda @
categoriespostgresql
postedNov 12, '08 at 10:54p
activeNov 12, '08 at 11:35p
posts3
users3
websitepostgresql.org.es
irc#postgresql

People

Translate

site design / logo © 2022 Grokbase