返回 table 个保留关键字的列名?

Returning table column names that are reserved key words?

我正在创建这个 return 是 table 的函数。我在下面代码的第 9 行遇到了这个问题,我相信 'position' 和下面的 'attribute' 列是主要问题。我想 return 列名与下面的代码完全一样。任何人都可以帮助我吗?提前致谢!

  CREATE OR REPLACE FUNCTION acc_qry_chart_of_account ( 
  type CHARACTER (3)='GL') RETURNS TABLE ( seqno SERIAL,
        acc_id INTEGER,
        parent_code CHARACTER (20),
        acc_code CHARACTER (20),
        description CHARACTER VARYING (120),
        description2 CHARACTER VARYING (120),
        acclevel INTEGER,
        position CHARACTER VARYING (120),
        attribute INTEGER,
        acctype CHARACTER (3),
        exttype CHARACTER(3)
  )
AS $$
DECLARE
....
BEGIN
....
END;
$$ LANGUAGE 'plpgsql'

你可以这样解决。 2 处更改。

  • 双引号列位置
  • 将 seqno 声明为整数。序列不是数据类型(它是使用序列的快捷方式)

新功能:

  CREATE OR REPLACE FUNCTION acc_qry_chart_of_account ( 
  type CHARACTER (3)='GL') RETURNS TABLE ( seqno integer,
        acc_id INTEGER,
        parent_code CHARACTER (20),
        acc_code CHARACTER (20),
        description CHARACTER VARYING (120),
        description2 CHARACTER VARYING (120),
        acclevel INTEGER,
        "position" CHARACTER VARYING (120),
        attribute INTEGER,
        acctype CHARACTER (3),
        exttype CHARACTER(3)
  )
AS $$
DECLARE
....
BEGIN
....
END;
$$ LANGUAGE 'plpgsql'