我有这个查询,它返回诊所、医生和可用预约的三级层次结构的平面表示:
select * from search_by_location(20,138.6,-34.9,null,0,0,1,99,current_date,7)
我正在尝试将其用作子查询来生成适当的三级层次结构:
with
a as (select * from search_by_location(20,138.6,-34.9,null,0,0,1,99,current_date,7)),
b as (
select business_name,
address1,
address2,
suburb,
postcode,
state_acronym,
phone_no,
latitude,
longitude,
clinic_url_display_name,
(first_name,
preferred_name,
last_name,
gender,
doctor_url_display_name,
gravatar_md5,
array_agg(appointment_start)
)::doctor_appointments_row doctor
from a
group by business_name,
address1,
address2,
suburb,
postcode,
state_acronym,
phone_no,
latitude,
longitude,
clinic_url_display_name,
first_name,
preferred_name,
last_name,
gender,
doctor_url_display_name,
gravatar_md5
)
select (business_name,
(address1,
address2,
suburb,
postcode,
state_acronym
)::address_row,
phone_no,
(latitude,
longitude)::coords_row,
clinic_url_display_name,
array_agg(doctor)
)::clinic_doctor_appointments_row clinic
from b
group by business_name,
address1,
address2,
suburb,
postcode,
state_acronym,
phone_no,
latitude,
longitude,
clinic_url_display_name
当我执行它时,我收到以下错误消息:
ERROR: malformed record literal: "0811112222"
DETAIL: Missing left parenthesis.
这很奇怪,因为我没有在查询中的任何地方指定该文字。它是来自基本查询的数据,特别是phone_no
列。知道是什么导致了这个错误以及如何解决它吗?
更新:
这运行没有错误(只是替换with
s 之后的查询部分):
with
a as (select * from search_by_location(20,138.6,-34.9,null,0,0,1,99,current_date,7)),
b as (
select business_name,
address1,
address2,
suburb,
postcode,
state_acronym,
phone_no,
latitude,
longitude,
clinic_url_display_name,
(first_name,
preferred_name,
last_name,
gender,
doctor_url_display_name,
gravatar_md5,
array_agg(appointment_start)
)::doctor_appointments_row doctor
from a
group by business_name,
address1,
address2,
suburb,
postcode,
state_acronym,
phone_no,
latitude,
longitude,
clinic_url_display_name,
first_name,
preferred_name,
last_name,
gender,
doctor_url_display_name,
gravatar_md5
)
select * from b
在这种情况下,没有嵌套 of array_agg
,我认为这可能是错误的。