Fórum Criação de function #26977
05/11/2008
0
Boas,
Tenho esta função:
create or replace function verif_estatuto() returns integer
as $verif_estatuto$
declare c integer;
begin
select count(*) into c
from socio
where nsocio=new.nsocio and honorario IS TRUE
return c;
end
$verif_estatuto$
language plpgsql;
e estas tabelas:
create table socio(
nsocio integer,
nome char(1024),
bi char(256) not null unique,
email char(256),
nif char(256) not null unique,
telefone char(256),
honorario boolean,
primary key(nsocio));
create table ano_mandato(
nsocio integer,
ano smallint not null,primary key(nsocio, ano),
foreign key(nsocio) references socio(nsocio));
Mas quando tenho criar a função obtenho este erro:
ERROR: NEW used in query that is not in a rule
QUERY: select count(*) from socio where nsocio=new.nsocio and honorario IS TRUE
return $1
CONTEXT: SQL statement in PL/PgSQL function ´verif_estatuto´ near line 6
Alguém me pode ajudar?
Tenho esta função:
create or replace function verif_estatuto() returns integer
as $verif_estatuto$
declare c integer;
begin
select count(*) into c
from socio
where nsocio=new.nsocio and honorario IS TRUE
return c;
end
$verif_estatuto$
language plpgsql;
e estas tabelas:
create table socio(
nsocio integer,
nome char(1024),
bi char(256) not null unique,
email char(256),
nif char(256) not null unique,
telefone char(256),
honorario boolean,
primary key(nsocio));
create table ano_mandato(
nsocio integer,
ano smallint not null,primary key(nsocio, ano),
foreign key(nsocio) references socio(nsocio));
Mas quando tenho criar a função obtenho este erro:
ERROR: NEW used in query that is not in a rule
QUERY: select count(*) from socio where nsocio=new.nsocio and honorario IS TRUE
return $1
CONTEXT: SQL statement in PL/PgSQL function ´verif_estatuto´ near line 6
Alguém me pode ajudar?
Bmrt82
Curtir tópico
+ 0
Responder
Posts
05/11/2008
Bmrt82
Já resolvi este problema, mas agora tenho outro na criação da trigger:
create trigger verif_estatuto_trigger before update or insert on ano_mandato
for each row execute procedure verif_estatuto(new.nsocio);
Mas dá-me este erro:
ERROR: syntax error at or near ´new´
LINE 2: for each row execute procedure verif_estatuto(new.nsocio);
create trigger verif_estatuto_trigger before update or insert on ano_mandato
for each row execute procedure verif_estatuto(new.nsocio);
Mas dá-me este erro:
ERROR: syntax error at or near ´new´
LINE 2: for each row execute procedure verif_estatuto(new.nsocio);
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)