使用规则在Insert上更新sql中的值;有OLD问题

时间:2016-10-04 01:37:44

标签: sql psql rule

当我有一张像

一样的桌子时
AccNum     Location
76         North
87         West
92         South

并说我想再次插入76但我只能在那里插入一次,所以在插入(76,东)我希望我的桌子看起来像

AccNum    Location
76        East
87        West
92        South

这是我的代码

CREATE RULE ChangeValue AS ON INSERT TO ItemLocations
     WHERE OLD.AccNum = NEW.AccNum
        DO INSTEAD
                UPDATE ItemLocations
                SET
                        Loc = NEW.Loc
                WHERE
                        AccNum = NEW.AccNum
;

但我现在正在

There is an entry for table "old", but it cannot be referenced from this part of the query.

感谢您

1 个答案:

答案 0 :(得分:0)

在Postgres 95. +中,您可以使用// add metabox to behind price product function meta_product() { // don't show in product --problem $new_meta2 = get_post_meta($post->ID,'_new_meta',true); echo $new_meta2; // show in product echo "123456"; } add_action('woocommerce_single_product_summary', 'meta_product',25);

on conflict

或者:

insert into t(AccNum, Location)
    select 76, 'East'
    on conflict do update set Location = 'East';