Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql “表”的条款条目中缺少;产品「;_Postgresql_Function_Triggers - Fatal编程技术网

Postgresql “表”的条款条目中缺少;产品「;

Postgresql “表”的条款条目中缺少;产品「;,postgresql,function,triggers,Postgresql,Function,Triggers,错误:表“product”的子句条目中缺少 我想在products.sellStatus=“seld”列的UPDATE之后更新列auctions.auctionStatus=“End”,其中(products.id”=auctions.idProduct) 所以我创建了一个触发器,但是我得到了一个错误。这使我无法更新表产品您不能像在函数中一样引用表。但由于这是一个触发器。您可以使用new记录访问更新行的值: 另外:在SQL中,字符串常量需要用单引号括起来,双引号仅用于标识符(应该像瘟疫一样避免)

错误:表“product”的子句条目中缺少

我想在
products.sellStatus=“seld”
列的
UPDATE
之后更新列
auctions.auctionStatus=“End”
,其中(products.id”=auctions.idProduct)


所以我创建了一个触发器,但是我得到了一个错误。这使我无法更新表产品

您不能像在函数中一样引用表。但由于这是一个触发器。您可以使用
new
记录访问更新行的值:

另外:在SQL中,字符串常量需要用单引号括起来,双引号仅用于标识符(应该像瘟疫一样避免)。
“已售出”
指的是一列,
“已售出”
是一个字符(字符串)值


与您的问题无关,但是:您应该真正避免那些可怕的引用标识符。他们的麻烦远比他们值得的多。
CREATE OR REPLACE FUNCTION update_sellstatus()
  RETURNS trigger AS
$body$
BEGIN
    if products."sellStatus" = "Sold" then
            update auctions
            set "auctionStatus" = "End"
            where (products."id" = auctions."idProduct");
        end if;
END
$body$
language plpgsql

create trigger update_sellStatus_auctionStatus
after update on products
for each row
    execute procedure update_sellstatus()
CREATE OR REPLACE FUNCTION update_sellstatus()
  RETURNS trigger AS
$body$
BEGIN
  if new."sellStatus" = 'Sold' then
    update auctions
      set "auctionStatus" = 'End'
    where auctions."idProduct" = new."id";
  end if;
END
$body$
language plpgsql