2

这是我的类型:

CREATE TYPE occupant AS (name text, title title);  

这是我的桌子:

CREATE TABLE office (id INTEGER DEFAULT NEXTVAL('venue_id_seq'),occupant occupant) INHERITS(venue);

然后这是我的功能:

 CREATE or REPLACE FUNCTION occupantName(id int) RETURNS text AS 
$$
  SELECT occupant.tile + occupant.name FROM office as v WHERE id = v.id;
$$ LANGUAGE SQL;

它给了我这个错误:

ERROR:  missing FROM-clause entry for table "ocupant"
LINE 15:       SELECT ocupant.tile + ocupant.name FROM office as v WH...
4

1 回答 1

5

您必须在 occupant 周围使用括号来访问复合类型字段:

CREATE or REPLACE FUNCTION occupantName(id int) RETURNS text AS 
$$
  SELECT (occupant).tile || (occupant).name FROM office as v WHERE id = v.id;
$$ LANGUAGE SQL;
于 2013-08-15T14:43:09.957 回答