简体   繁体   English

出现语法错误:运行“立即执行”时意外的关键字 END

[英]Getting Syntax Error: Unexpected keyword END while running `Execute Immediate`

I am trying to execute following set of statements in Bigquery.我正在尝试在 Bigquery 中执行以下一组语句。 However, I get a syntax error as I execute this statement.但是,在执行此语句时出现语法错误。

Below is the query.下面是查询。 I have removed the DB and table names.我已经删除了数据库和表名。

DECLARE
  fields STRING;
DECLARE
  updates STRING;
DECLARE
  project_dataset STRING;
DECLARE
  table_data STRING;
DECLARE
  table_changes STRING;
SET
  project_dataset = '<DB NAME>';
SET
  table_data = '<Table name>';
SET
  table_changes = '<Table names>';
EXECUTE IMMEDIATE
  ( "SELECT STRING_AGG(column_name) FROM `"||project_dataset||"`.INFORMATION_SCHEMA.COLUMNS WHERE table_name = '"||table_data||"'" ) INTO fields;
EXECUTE IMMEDIATE
  ( """WITH t AS (SELECT column_name FROM `"""||project_dataset||"""`.INFORMATION_SCHEMA.COLUMNS WHERE table_name = '"""||table_data||"""')
       SELECT STRING_AGG("t."||column_name ||" = "|| "s."||column_name) from t join t as s using(column_name)""" ) INTO updates;
EXECUTE IMMEDIATE
  """
  MERGE `"""||project_dataset||"."||table_data||"""` T
  USING `"""||project_dataset||"."||table_changes||"""` S
    ON T.id = S.id
  WHEN MATCHED AND S.updated_at > T.updated_at THEN 
    UPDATE SET """||updates||"""
  WHEN NOT MATCHED THEN
    INSERT ("""||fields||") VALUES ("||fields||")";

The error:错误:

Invalid EXECUTE IMMEDIATE sql string ` MERGE `healthie_test.appointments` T USING `healthie_test.appointments_fresh` S ON T.id = S.id WHEN MATCHED AND S.updated_at > T.updated_at THEN UPDATE SET t.actual_duration = s.actual_duration,t.add_to_gcal_link = s.add_to_gcal_link,t.appointment_category = s.appointment_category,t.appointment_inclusions_count = s.appointment_inclusions_count,t.appointment_label = s.appointment_label,t.appointment_location_id = s.appointment_location_id,t.appointment_type = s.appointment_type,t.appointment_type_id = s.appointment_type_id,t.assigned_groups = s.assigned_groups,t.attended_clients = s.attended_clients,t.attendees = s.attendees,t.attendees_on_waitlist = s.attendees_on_waitlist,t.backgroundColor = s.backgroundColor,t.can_be_rescheduled = s.can_be_rescheduled,t.can_client_cancel = s.can_client_cancel,t.can_client_reschedule = s.can_client_reschedule,t.client_confirmed = s.client_confirmed,t.connected_chart_note_locked = s.connected_chart_note_locked,t.connected_chart_note_string = s.connected_chart_note_string,t.contact_type = s.contact_type,t.conversation_id = s.conversation_id,t.created_at = s.created_at,t.current_position_in_recurring_series = s.current_position_in_recurring_series,t.date = s.date,t.default_color = s.default_color,t.end = s.end,t.external_id_type = s.external_id_type,t.external_videochat_url = s.external_videochat_url,t.filled_embed_form = s.filled_embed_form,t.form_answer_group = s.form_answer_group,t.generated_token = s.generated_token,t.id = s.id,t.initiator_id = s.initiator_id,t.is_blocker = s.is_blocker,t.is_group = s.is_group,t.is_zoom_chat = s.is_zoom_chat,t.last_client_conversation_id = s.last_client_conversation_id,t.length = s.length,t.location = s.location,t.locationResource = s.locationResource,t.max_attendees = s.max_attendees,t.minimum_advance_cancel_time = s.minimum_advance_cancel_time,t.minimum_advance_reschedule_time = s.minimum_advance_reschedule_time,t.notes = s.notes,t.other_party_id = s.other_party_id,t.patient_reschedule_count = s.patient_reschedule_count,t.pm_status = s.pm_status,t.provider = s.provider,t.providers = s.providers,t.reason = s.reason,t.recurring_appointment = s.recurring_appointment,t.requested_payment = s.requested_payment,t.resourceId = s.resourceId,t.room_id = s.room_id,t.scheduled_by = s.scheduled_by,t.session_id = s.session_id,t.start = s.start,t.textColor = s.textColor,t.time_recurring_override = s.time_recurring_override,t.timezone_abbr = s.timezone_abbr,t.title = s.title,t.updated_at = s.updated_at,t.use_zoom = s.use_zoom,t.user = s.user,t.user_id = s.user_id,t.zoom_appointment = s.zoom_appointment,t.zoom_cloud_recording_urls = s.zoom_cloud_recording_urls,t.zoom_dial_in_info = s.zoom_dial_in_info,t.zoom_dial_in_info_html = s.zoom_dial_in_info_html,t.zoom_dial_in_numbers_json = s.zoom_dial_in_numbers_json,t.zoom_join_url = s.zoom_join_url,t.zoom_meeting_id = s.zoom_meeting_id,t.zoom_start_url = s.zoom_start_url WHEN NOT MATCHED THEN INSERT (actual_duration,add_to_gcal_link,appointment_category,appointment_inclusions_count,appointment_label,appointment_location_id,appointment_type,appointment_type_id,assigned_groups,attended_clients,attendees,attendees_on_waitlist,backgroundColor,can_be_rescheduled,can_client_cancel,can_client_reschedule,client_confirmed,connected_chart_note_locked,connected_chart_note_string,contact_type,conversation_id,created_at,current_position_in_recurring_series,date,default_color,end,external_id_type,external_videochat_url,filled_embed_form,form_answer_group,generated_token,id,initiator_id,is_blocker,is_group,is_zoom_chat,last_client_conversation_id,length,location,locationResource,max_attendees,minimum_advance_cancel_time,minimum_advance_reschedule_time,notes,other_party_id,patient_reschedule_count,pm_status,provider,providers,reason,recurring_appointment,requested_payment,resourceId,room_id,scheduled_by,session_id,start,textColor,time_recurring_override,timezone_abbr,title,updated_at,use_zoom,user,user_id,zoom_appointment,zoom_cloud_recording_urls,zoom_dial_in_info,zoom_dial_in_info_html,zoom_dial_in_numbers_json,zoom_join_url,zoom_meeting_id,zoom_start_url) VALUES (actual_duration,add_to_gcal_link,appointment_category,appointment_inclusions_count,appointment_label,appointment_location_id,appointment_type,appointment_type_id,assigned_groups,attended_clients,attendees,attendees_on_waitlist,backgroundColor,can_be_rescheduled,can_client_cancel,can_client_reschedule,client_confirmed,connected_chart_note_locked,connected_chart_note_string,contact_type,conversation_id,created_at,current_position_in_recurring_series,date,default_color,end,external_id_type,external_videochat_url,filled_embed_form,form_answer_group,generated_token,id,initiator_id,is_blocker,is_group,is_zoom_chat,last_client_conversation_id,length,location,locationResource,max_attendees,minimum_advance_cancel_time,minimum_advance_reschedule_time,notes,other_party_id,patient_reschedule_count,pm_status,provider,providers,reason,recurring_appointment,requested_payment,resourceId,room_id,scheduled_by,session_id,start,textColor,time_recurring_override,timezone_abbr,title,updated_at,use_zoom,user,user_id,zoom_appointment,zoom_cloud_recording_urls,zoom_dial_in_info,zoom_dial_in_info_html,zoom_dial_in_numbers_json,zoom_join_url,zoom_meeting_id,zoom_start_url)`, Syntax error: Unexpected keyword END at [24:3]

This is the position 24:3 Screenclip这是 position 24:3 Screenclip

While there is no any "END" keyword in query, I am not sure why I am getting this error.虽然查询中没有任何“END”关键字,但我不确定为什么会出现此错误。 Kindly guide.请指导。

I made sure that the string literals are properly enclosed.我确保字符串文字被正确括起来。 Other than that I am not really sure what is wrong.除此之外,我不太确定哪里出了问题。

From a quick glance, it looks like you're projecting a column called end which is a reserved word .快速浏览一下,您似乎正在投影一个名为end的列,这是一个保留字

See the section on quoting identifiers for how to handle this properly (TL;DR - enclose in backticks).请参阅有关引用标识符的部分以了解如何正确处理此问题(TL; DR - 用反引号括起来)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM