记录"new"没有字段"cure" postgreSQL



所以事情是这样的,我有两个表:apointments(带有单个p(和medical_folder,我得到了这个

错误:记录"new"没有字段"固化" 上下文:SQL 语句"insert into medical_folder(id,"patient_AMKA",cure,drug_id( 值(new.id,new."patient_AMKA",新治愈,new.drug_id(" PL/pgSQL 函数 new_medical(( 第 3 行在 SQL 语句中

create trigger example_trigger after insert on apointments 
for each row execute procedure new_medical();
create or replace function new_medical()
returns trigger as $$
begin 
if apointments.diagnosis is not null then
insert into medical_folder(id,"patient_AMKA",cure,drug_id)
values(new.id,new."patient_AMKA",new.cure,new.drug_id);
return new;
end if;
end;
$$ language plpgsql;

insert into apointments(id,time,"patient_AMKA","doctor_AMKA",diagnosis)
values('30000','2017-05-24 0 
07:42:15','4017954515276','6304745877947815701','M3504');

我已经检查了多次,我所有的表和列都存在请帮忙!谢谢!

表结构包括:

create table medical_folder (
  id      bigInt,
  patient bigInt,
  cure    text,
  drug_id bigInt);
create table apointments (
  id      bigint,
  time    timestamp without time zone,
  "patient_AMKA" bigInt,
  "doctor_AMKA"  bigInt);

我遇到了同样的问题。改变:

values(new.id,new."patient_AMKA",new.cure,new.drug_id);

自:

values(new.id,new."patient_AMKA",new."cure",new."drug_id");

此错误表示表点(带 1 p(没有名为 cure 的字段。插入点时会发生触发器,因此"new"是点行。也许它是诊断对象的一部分?

第二个表的值在"新建"行中不可用。您需要一种方法来获取和插入它们,而使用触发器并不是最简单/干净的方法。您可以让应用程序执行两次插入,一次按表执行,并将它们包装在事务中,以确保它们都已提交/回滚。另一个选项(可让您更好地强制实施数据完整性(是创建一个存储过程,该过程将要插入的值插入到两个表中并执行两次插入。您可以禁止用户写入表,从而有效地使存储过程成为插入数据的唯一方法。

最新更新