PostgreSQL plpgsql

编程入门 行业动态 更新时间:2024-10-28 10:25:04
本文介绍了PostgreSQL plpgsql-变量列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在创建一个触发器,该触发器为列使用动态名称

I am creating a trigger, which uses dynamic names for columns

NEW.name:=2222; -- works fine !

但是

dynamic_column:='name'; EXECUTE '$1.'||dynamic_column||':=2222 ' USING NEW; -- raises error

出现错误:

错误:"$ 1"或附近的语法错误LINE 1:$ 1.name:= 2222

ERROR: syntax error at or near "$1" LINE 1: $1.name:=2222

推荐答案

我在这里找到了信息:通过键入Postgres触发器分配为NEW

I found info here: Assign to NEW by key in a Postgres trigger

如果我们通过以下方式启用hstore模块:

If we enable the module hstore by:

CREATE EXTENSION hstore;

我们可以这样做:

dynamic_column:='name'; temp_sql_string:='"'||dynamic_column||'"=>"2222"'; NEW := NEW #= temp_sql_string::hstore;

现在将RECORD NEW.name设置为值2222.

And the RECORD NEW.name now is set to the value 2222.

感谢您努力寻找解决方案@Laurenz Albe

Thank you tough for making an effort to find a solution @Laurenz Albe

更多推荐

PostgreSQL plpgsql

本文发布于:2023-07-20 22:03:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1171491.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PostgreSQL   plpgsql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!