0

我有这个查询,它返回诊所、医生和可用预约的三级层次结构的平面表示:

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列。知道是什么导致了这个错误以及如何解决它吗?

更新:

这运行没有错误(只是替换withs 之后的查询部分):

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,我认为这可能是错误的。

4

1 回答 1

0

我打赌你在运行你的函数时会遇到同样的错误,而你真正的问题在于返回类型。这是我能发现的唯一可能的地方,除非问题比你说的要多。

我的想法是你应该试着跑

 select * from search_by_location(20,138.6,-34.9,null,0,0,1,99,current_date,7)

第一的。确保它有效。如果是的话,那么......

仔细查看运行其他查询的上下文。我的猜测是它在一个试图转换为记录或其他东西的函数中运行,

于 2013-09-22T08:02:44.503 回答