Postgres function NULL value for row that references NEW

后端 未结 1 1590
旧时难觅i
旧时难觅i 2020-12-12 07:57

I have a trigger setup to fire after a row is updated or inserted for table A. There is also a table B that references table A, but also has another column which I want to a

相关标签:
1条回答
  • 2020-12-12 08:24

    Most probably you are running into a naming conflict. Parameter names (IN and OUT parameters) are visible in the function body (almost) anywhere and take precedence over unqualified column names. Did you declare col1 as variable in the function?

    To avoid the conflict, table-qualify the column name:

    SELECT b.col1 FROM tableb b WHERE b.aID = NEW.ID;
    

    This is good practice in any case.

    It is also good practice to prefix variable names, so they wouldn't normally conflict with table columns. Like: _col1.

    0 讨论(0)
提交回复
热议问题