如何在plpgsql函数中获取表的键字段? [英] How to get the key fields for a table in plpgsql function?
问题描述
我需要创建一个将在每次UPDATE和INSERT操作之后触发的函数,并检查在某些条件下执行该操作的表的关键字段.
I need to make a function that would be triggered after every UPDATE and INSERT operation and would check the key fields of the table that the operation is performed on vs some conditions.
该函数(和触发器)必须是通用的,它不应该对表名/字段名进行硬编码.
The function (and the trigger) needs to be an universal one, it shouldn't have the table name / fields names hardcoded.
我被困在需要访问表名称及其架构部分的部分-检查哪些字段是PRIMARY KEY的一部分.
I got stuck on the part where I need to access the table name and its schema part - check what fields are part of the PRIMARY KEY.
推荐答案
After getting the primary key info as already posted in the first answer you can check the code in http://github.com/fgp/pg_record_inspect to get record field values dynamicaly in PL/pgSQL.
这篇关于如何在plpgsql函数中获取表的键字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!