我有一个名为“地址”的复合字段。它有字段: - 街道名称 - 街牌号码 - 区域
如果我做正常选择:
select address from mytable where id = 1
我明白了:
address => ("my street",1,earth)
我想要一种方法来选择它并得到:
street_name => my street
street_number => 1
area => earth
过去我设法做到了这样做:
select address.* from mytable where id = 1
但这不起作用。任何想法如何以我想要的方式获得结果?
答案 0 :(得分:2)
根据manual。如果您尝试引用复合类型的子字段,则需要将名称放在括号中,否则解析器会认为您正在尝试从“地址”表中获取某些内容
SELECT (address).* from mytable where id = 1
答案 1 :(得分:0)
如果您只想选择元素,请执行以下操作:
select address.street_name,
address.street_number,
address.area
from mytable where id = 1
如果您希望结果与您的问题完全一致:
select 'street_name =>' || address.street_name
from mytable where id = 1 union
select 'street_number =>' || address.street_number
from mytable where id = 1 union
select 'area=>' || address.area
from mytable where id = 1