extract values inside an array column in amazon athena - sql
I have a table in athena aws where the column 'metadata_stopinfo' has the structure that you can see in the image.
I am trying to extract values that are inside that array, however when I try
SELECT
"json_extract_scalar"(metadata_stopinfo, '$.city')
FROM "table"
I have the following problem
SYNTAX_ERROR: line 2:5: Unexpected parameters (array(row("address" row("addressline" varchar,"city" varchar,"countrycode" varchar,"countrycodeoriginal" varchar,"state" varchar,"zipcode" varchar),"carrierreference" varchar,"contacts" array(row("contacttype" varchar,"email" varchar,"fax" varchar,"mobilephone" varchar,"name" varchar,"officephone" varchar,"userid" varchar)),"containerinfo" array(row("containerid" varchar,"containeridtype" varchar,"equipmentcode" varchar,"equipmenttype" varchar)),"conveyancelinenumber" varchar,"conveyancetype" varchar,"conveyancetypeoriginal" varchar,"dateinfo" row("arrivalestimateddate" varchar,"arrivalestimateddateend" varchar,"arrivalestimatedendoffset" varchar,"arrivalestimatedoffset" varchar,"arrivalrequesteddate" varchar,"deliveryestimateddate" varchar,"deliveryestimateddateend" varchar,"deliveryestimatedendoffset" varchar,"deliveryestimatedoffset" varchar,"deliveryrequesteddate" varchar,"deliveryrequesteddateend" varchar,"deliveryrequestedendoffset" varchar,"deliveryrequestedoffset" varchar,"departureestimateddate" varchar,"departureestimateddateend" varchar,"departureestimatedendoffset" varchar,"departureestimatedoffset" varchar,"departurerequesteddate" varchar,"pickuprequesteddate" varchar,"pickuprequesteddateend" varchar,"pickuprequestedendoffset" varchar,"pickuprequestedoffset" varchar,"pickupestimateddate" varchar,"pickupestimateddateend" varchar,"pickupestimatedendoffset" varchar,"pickupestimatedoffset" varchar),"deliverynotenumber" varchar,"instructions" array(row("customerspecificsubtype" varchar,"header" boolean,"instructionsubtype" varchar,"instructiontype" varchar,"text" varchar)),"locationid" varchar,"partnercarrieraddress" row("addressline" varchar,"city" varchar,"countrycode" varchar,"countrycodeoriginal" varchar,"state" varchar,"zipcode" varchar),"partnercarriercontacts" array(row("contacttype" varchar,"email" varchar,"fax" varchar,"name" varchar,"officephone" varchar)),"partnercarrierid" varchar,"partnercarriername" varchar,"partnerid" varchar,"partnername" varchar,"partnertimezone" varchar,"partnertype" varchar,"productquantity" row("number" double,"originalunitofmeasure" varchar,"quantitytype" varchar,"unitofmeasure" varchar),"sequencenumber" bigint,"shipmentidentifier" varchar,"stoptype" varchar,"transportinfo" row("description" varchar,"transportcode" varchar,"transportoriginalcode" varchar),"vesselinfo" row("lloydsnumber" varchar,"shipsradiocallnumber" varchar,"vesselname" varchar,"vesselnumber" varchar,"voyagetripnumber" varchar))), varchar(6)) for function json_extract_scalar. Expected: json_extract_scalar(varchar(x), JsonPath) , json_extract_scalar(json, JsonPath)
My question is, how can i extract values inside de column ?
json_extract_scalar unsurprisingly works with json (note that even if yur data was in json format, json_extract_scalar(metadata_stopinfo, '$.city') still would not have worked cause your data is an array), while your column contains array's of row's, so you need to work with it correspondingly. For example you can use indexes to access elements in array (in presto array indexes start from 1):
SELECT
metadata_stopinfo[1] r
FROM "table"
And then access the fields:
The fields may be of any SQL type, and are accessed with field reference operator .
SELECT
metadata_stopinfo[1].city city
FROM "table"
Also you can flatten the array with unnest:
SELECT r.city
FROM "table",
unnest(metadata_stopinfo) as t(r)
Related
Transforming JSON data to relational data
I want to display data from SQL Server where the data is in JSON format. But when the select process, the data does not appear: id item_pieces_list 0 [{"id":2,"satuan":"BOX","isi":1,"aktif":true},{"id":4,"satuan":"BOX10","isi":1,"aktif":true}] 1 [{"id":0,"satuan":"AMPUL","isi":1,"aktif":"true"},{"id":4,"satuan":"BOX10","isi":5,"aktif":true}] I've written a query like this, but nothing appears. Can anyone help? Query : SELECT id, JSON_Value(item_pieces_list, '$.satuan') AS Name FROM [cisea.bamedika.co.id-hisys].dbo.medicine_alkes AS medicalkes
Your Path is wrong. Your JSON is an array, and you are trying to retrieve it as a flat object SELECT id, JSON_Value(item_pieces_list,'$[0].satuan') AS Name FROM [cisea.bamedika.co.id-hisys].dbo.medicine_alkes Only in the case of data without the [] (array sign) you could use your original query '$.satuan', but since you are using an array I change it to retrieve only the first element in the array '$[0].satuan'
Presto extract string from array of JSON elements
I am on Presto 0.273 and I have a complex JSON data from which I am trying to extract only specific values. First, I ran SELECT JSON_EXTRACT(library_data, '.$books') which gets me all the books from a certain library. The problem is this returns an array of JSON objects that look like this: [{ "book_name":"abc", "book_size":"453", "requestor":"27657899462" "comments":"this is a comment" }, { "book_name":"def", "book_size":"354", "requestor":"67657496274" "comments":"this is a comment" }, ... ] I would like the code to return just a list of the JSON objects, not an array. My intention is to later be able to loop through the JSON objects to find ones from a specific requester. Currently, when I loop through the given arrays using python, I get a range of errors around this data being a Series, hence trying to extract it properly rather. I tried this SELECT JSON_EXTRACT(JSON_EXTRACT(data, '$.domains'), '$[0]') but this doesn't work because the index position of the object needed is not known. I also tried SELECT array_join(array[books], ', ') but getting "Error casting array element to VARCHAR " error. Can anyone please point me in the right direction?
Cast to array(json): SELECT CAST(JSON_EXTRACT(library_data, '.$books') as array(json)) Or you can use it in unnest to flatten it to rows: SELECT *, js_obj -- will contain single json object FROM table CROSS JOIN UNNEST CAST(JSON_EXTRACT(library_data, '.$books') as array(json)) as t(js_obj)
Extracting JSON returns null (Presto Athena)
I'm working with SQL Presto in Athena and in a table I have a column named "data.input.additional_risk_data.basket" that has a json like this: [ { "data.input.additional_risk_data.basket.val.brand":null, "data.input.additional_risk_data.basket.val.category":null, "data.input.additional_risk_data.basket.val.item_reference":"26484651", "data.input.additional_risk_data.basket.val.name":"Nike Force 1", "data.input.additional_risk_data.basket.val.product_name":null, "data.input.additional_risk_data.basket.val.published_date":null, "data.input.additional_risk_data.basket.val.quantity":"1", "data.input.additional_risk_data.basket.val.size":null, "data.input.additional_risk_data.basket.val.subCategory":null, "data.input.additional_risk_data.basket.val.unit_price":769.0, "data.input.additional_risk_data.basket.val.upc":null, "data.input.additional_risk_data.basket.val.url":null } ] I need to extract some of the data there, for example data.input.additional_risk_data.basket.val.item_reference. I'm not used to working with jsons but I tried a few things: json_extract("data.input.additional_risk_data.basket", '$.data.input.additional_risk_data.basket.val.item_reference') json_extract_scalar("data.input.additional_risk_data.basket", '$.data.input.additional_risk_data.basket.val.item_reference) They all returned null. I'm wondering what is the correct way to get the values from that json Thank you!
There are multiple "problems" with your data and json path selector. Keys are not conventional (and I have not found a way to tell athena to escape them) and your json is actually an array of json objects. What you can do - cast data to an array and process it. For example: -- sample data WITH dataset (json_val) AS ( VALUES (json '[ { "data.input.additional_risk_data.basket.val.brand":null, "data.input.additional_risk_data.basket.val.category":null, "data.input.additional_risk_data.basket.val.item_reference":"26484651", "data.input.additional_risk_data.basket.val.name":"Nike Force 1", "data.input.additional_risk_data.basket.val.product_name":null, "data.input.additional_risk_data.basket.val.published_date":null, "data.input.additional_risk_data.basket.val.quantity":"1", "data.input.additional_risk_data.basket.val.size":null, "data.input.additional_risk_data.basket.val.subCategory":null, "data.input.additional_risk_data.basket.val.unit_price":769.0, "data.input.additional_risk_data.basket.val.upc":null, "data.input.additional_risk_data.basket.val.url":null } ]') ) --query select arr[1]['data.input.additional_risk_data.basket.val.item_reference'] item_reference -- or use unnest if there are actually more than 1 element in array expected from( select cast(json_val as array(map(varchar, json))) arr from dataset ) Output: item_reference "26484651"
How to query on array of struct column in AWS Athena? (parquet format)
I have a array of struct column in table reports. (array<struct< key:string,value:string>>) the columns data look like labels --------------------------------------------------------------------------- [{key=name, value=cat}, {key=owner, value=meow}, {key=team, value=animal}]` [] [{key=name, value=leopard}] How can I query this where I wanted to find records which has key=name and value=cat, and key=owner and value=meow. (i mean the first example).
Check the below link. This is cloudtrail logs, where we have struct columns https://docs.aws.amazon.com/athena/latest/ug/cloudtrail-logs.html Refer to the userIdentity column Also check below link https://docs.aws.amazon.com/athena/latest/ug/rows-and-structs.html You can directly reference nested fields with a parent_field.child_field notation. Try: SELECT my_field, my_field.a, my_field.b, my_field.c.d, my_field.c.e FROM my_table
PgSQL insert into select after cast
I have a table with many columns stored as text. These columns have information which i am planning to cast and copy the data into a fresh table with the same column names but with correct data types ( float8 ) I tested the SELECT with CAST operator "::" and it works fine. All the columns are being converted as you can see in the picture However , when I uncomment the INSERT statement ( above it ) to start writing in the target table, it throws an error. The target table has identical column names and only float8 column types. The expression from the source table is indeed of type text but i am using the cast operator so why does it not work like before when only running the SELECT statement? My query below: INSERT INTO "PM"."new_VM_gcell_evolution_hourly_BSC" (select "CR3120:Channel_Assignment_Failures_All_Channels_Busy_or_Channel"::float8, "DL_Mean_Quality"::float8, "A312Ca:Failed_Assignments_during_MTC_on_the_A_Interface_Includi"::float8, "nsp_Urban_TA_4number"::float8, "A3129C:Failed_Assignments_First_Assignment,_Assignment_Timed_Ou"::float8, "R3120C:Channel_Assignment_Failures_All_Channels_Busy_or_Channel"::float8, "TSs_Interf_B5"::float8, "R3120D:Channel_Assignment_Failures_All_Channels_Busy_or_Channel"::float8, "HO_Out_Internal_Succ_Rate"::float8, "CH_Req_Protocol_Undefinednbnumber"::float8, "UL_Drop_Congnumber"::float8, "Timing_Adv"::float8, "DL_Qual"::float8, "A3100C:Assignment_Requests_TCHH_Only"::float8, "MS_to_BTS_max_distance"::float8, "TSs_Interf_B2"::float8, "UL_Qual"::float8, "UL_Drop_EDGE_Rate"::float8, "Avg_BTS_Power_Level_AMR"::float8, "DL_Drop_N3105number"::float8, "nsp_Urban_TA_2_R"::float8, "CH_Req_CallReestabnbnumber"::float8, "TCH_Drops_cause_Timing_Advance"::float8, "TCH_Drops_per_Erlang"::float8, "UL_Drop_Flushnumber"::float8, "A312F:Number_of_Assignment_Failures_No_Abis_Resource_Available"::float8, "UL_Drop_GPRS_Rate"::float8, "nsp_Urban_TA_3number"::float8, "Call_Drop_rate"::float8, "DL_Fail_Assingnumber"::float8, "SDCCH_Radio_Failures"::float8, "HO_Cmd_UL_Qual"::float8, "UL/DL_RxQualnumber"::float8, "UL/DL_RxLevnumber"::float8, "UL_Fail_EDGE_Rate"::float8, "Call_Drop_Total"::float8, "HO_Out_Succ_Rate"::float8, "Date"::text, "A3127E:Failed_Assignments_during_Call_Reestablishment_on_the_Um"::float8, "UL_Drop_N3103number"::float8, "Configured_TCH"::float8, "SDCCH_Drop_Call_Rate_only_LU"::float8, "A312M:Failed_Assignments_Reconnection_to_Old_Channels,_No_Chann"::float8, "SDCCH_Blocking_Rate"::float8, "TCH_Drops_cause_DL_FER"::float8, "TCH_Fail_rate"::float8, "DL_Drop_Preemnumber"::float8, "FR_Traffic_totalErl"::float8, "DL_Congnumber"::float8, "TCH_Assign_Unsuccnumber"::float8, "nsp_Urban_TA_0_R"::float8, "DL_Drop_GPRS_Rate"::float8, "HR_TraficErl"::float8, "SDCCH_Cong_Rate"::float8, "Abis_and_Ater_Interface_Anlysistimes"::float8, "A3100B:Assignment_Requests_TCHF_Only"::float8, "AS4300D:Mean_Uplink_Level_during_Radio_Link_Failure_SDCCHdB"::float8, "nsp_Urban_TA_89number"::float8, "TCH_Drops_cause_DownQual"::float8, "SDCCH_Drop_RxLev"::float8, "Max_UL_Pwr_Duration"::float8, "nsp_Channel_Req_LUnumber"::float8, "TCH_HR_Initialy_Config"::float8, "HO_Inc_Cong_Rate"::float8, "DL_RxLev_avgdBm"::float8, "TCH_Assign_Requestsnumber"::float8, "A312K:Failed_Assignments_First_Assignment,_No_Channel_Available"::float8, "Call_Drop_TCH_Quality_Rate"::float8, "AMR_HR_TraficErl"::float8, "nsp_Urban_TA_67_R"::float8, "UL_Fail_MSnumber"::float8, "Time"::text, "TCH_Drops_cause_UpLevel"::float8, "AMR_FR_TraficErl"::float8, "TCH_FR_Initialy_Config"::float8, "UL_Drop_N3101number"::float8, "DL_FERnumber"::float8, "SDCCH_Drop_Call_Rate_wo_LU"::float8, "DL_Mean_StrengthdB"::float8, "Call_Drop_Abis"::float8, "SDCCH_Initialy_Confignumber"::float8, "Call_Drop_TCH_RxLev_Rate"::float8, "TA_Meannumber"::float8, "nsp_Urban_TA_67number"::float8, "AS3240NA:Average_MS_Power_Level_of_NonAMR_Call"::float8, "Load"::float8, "A3129Q:Failed_Assignments_Reconnection_to_Old_Channels,_Timer_E"::float8, "CH_Request_11_bit"::float8, "AS4340D:Mean_TA_during_Radio_Link_Failure_SDCCH"::float8, "S4210A:Uplink_Interference_Indication_Messages_SDCCH"::float8, "UL_FERnumber"::float8, "A3129P:Failed_Assignments_Reconnection_to_Old_Channels,_Timer_E"::float8, "K3003A:Successful_SDCCH_Seizures_Call_Type"::float8, "CH_Req_LAUnbnumber"::float8, "SDCCH_Drop_Rate"::float8, "GBSC"::text, "CS_CSSR_with_SDCCH_blocks_wo_LU"::float8, "A312Aa:Failed_Assignments_during_MOC_on_the_A_Interface_Includi"::float8, "Avg_BTS_Power_Level"::float8, "R3120A:Channel_Assignment_Failures_All_Channels_Busy_or_Channel"::float8, "A312S:Failed_Assignments_Signaling_Channel"::float8, "SD_Fail_MoC"::float8, "UL_RxQual_avg"::float8, "Call_Drop_HO"::float8, "AS4330D:Mean_Downlink_Quality_during_Radio_Link_Failure_SDCCH"::float8, "CH_Req_Emerg_Callsnbnumber"::float8, "UL_RxQualnumber"::float8, "UL_Fail_OtherCausenumber"::float8, "A312Da:Failed_Assignments_during_Emergency_Call_on_the_A_Interf"::float8, "UL_Drop_Preemnumber"::float8, "TCH_Drops_cause_UpDown_FER"::float8, "AS4320D:Mean_Downlink_Level_during_Radio_Link_Failure_SDCCHdB"::float8, "A3129O:Failed_Assignments_First_Assignment,_Directed_Retry_Time"::float8, "Max_DL_Pwr_Duration"::float8, "UL_Drop_Suspendnumber"::float8, "TCH_Assign_Congestionnumber"::float8, "Transmission_Resource_Analysistimes"::float8, "HO_Out_RxQual_rate"::float8, "nsp_Urban_TA_1013number"::float8, "A3129I:Failed_Assignments_Invalid_State"::float8, "DL_Fail_OtherCausenumber"::float8, "CR3129:Channel_Assignment_Failures_All_Channels_Busy_or_Channel"::float8, "HO_Inc_Successnumber"::float8, "A3129B:Failed_Assignments_First_Assignment,_Terrestrial_Resourc"::float8, "Trafic_totalErl"::float8, "nsp_urban_TA_1463all_R"::float8, "HO_Out_RxQualnumber"::float8, "DL_RxQualnumber"::float8, "HO_Inc_Succ_Rate"::float8, "SDCCH_Fail_Rate"::float8, "SDCCH_Non_Radio_Drops"::float8, "nsp_Urban_TA_0number"::float8, "A3129E:Failed_Assignments_CIC_Unavailable"::float8, "nsp_CH_Request_PSnumber"::float8, "TCH_Assign_Unsucc_rate"::float8, "Call_Drop_Radio"::float8, "EFR_TraficErl"::float8, "A312L:Failed_Assignments_Reconnection_to_Old_Channels,_No_Chann"::float8, "TCH_Drops_cause_DownLevel"::float8, "nsp_Urban_TA_5number"::float8, "Abnormal_Terminals_Analysistimes"::float8, "HO_Inc_Congnumber"::float8, "CSSR_Rate"::float8, "M3020C:Call_Drops_on_SDCCHQuality"::float8, "RH333:Handover_Drop_Rate_of_TCH"::float8, "UL_Drop_EDGE_Abisnumber"::float8, "A3129J:Failed_Assignments_Invalid_Message"::float8, "TCH_Availability"::float8, "UL_Level"::float8, "nsp_Urban_TA_4_R"::float8, "UL_Drop_OtherCausenumber"::float8, "HR_Traffic_Rate"::float8, "DL_Level"::float8, "CH_Request_8_bit"::float8, "UL_Fail_MS_Assingnumber"::float8, "DL_Fail_BSC_Commandnumber"::float8, "A3129R:Failed_Assignments_Reconnection_to_Old_Channels,_Reconne"::float8, "UL_Fail_BSC_Commandnumber"::float8, "DL_Drop_Suspendnumber"::float8, "nsp_urban_TA_1463allnumber"::float8, "Direct_Retry"::float8, "nsp_Urban_TA_89_R"::float8, "CH_Req_PSnbnumber"::float8, "A3129N:Failed_Assignments_Reconnection_to_Old_Channels,_Terrest"::float8, "A312A:Failed_Assignments_First_Assignment,_No_Channel_Available"::float8, "nsp_Urban_TA_2number"::float8, "DL_RxQual_avg"::float8, "UL_Mean_StrengthdB"::float8, "DL_Drop_EDGE_Rate"::float8, "A3129T:Failed_Assignments_No_Ater_Resource_Available"::float8, "TSs_Interf_B1"::float8, "A3129D:Failed_Assignments_Reconnection_to_Old_Channels,_Reconne"::float8, "nsp_Channel_Req_MOCnumber"::float8, "UL_Fail_GPRS_Rate"::float8, "S4210B:Downlink_Interference_Indication_Messages_SDCCH"::float8, "R3120E:Channel_Assignment_Failures_All_Channels_Busy_or_Channel"::float8, "HO_Inc_Failnumber"::float8, "DL_Drop_Flushnumber"::float8, "S3655:Number_of_configured_TRXs_in_a_cell"::float8, "TCH_Drops_cause_UpDown_Qual"::float8, "CR3005:Number_of_Initially_Configured_Channels_Static_PDTCH_Sup"::float8, "UL/DL_FERnumber"::float8, "SDCCH_Blocking_"::float8, "HO_Out_InterRAT_Succ_Rate"::text, "CM30E:Call_Drops_on_SDCCH_Location_Updating"::float8, "AS4310D:Mean_Uplink_Quality_during_Radio_Link_Failure_SDCCH"::float8, "UL_Congnumber"::float8, "TAnumber"::float8, "Configured_SDCCH"::float8, "Othernumber"::float8, "TCH_Assign_Fail_Radionumber"::float8, "HO_Out_Internal_Req_Nb"::float8, "SDCCH_Cong_Nbnumber"::float8, "UL_Mean_Quality"::float8, "HO_Out_External_Req_Nb"::float8, "nsp_Urban_TA_1013_R"::float8, "SDCCH_Drops_wo_LU"::float8, "Call_Drop_TCH_Qualitynumber"::float8, "A3100A:Assignment_Requests_Signaling_Channel_TCH"::float8, "Better_Cell"::float8, "Call_Drop_TCH_RxLevnumber"::float8, "nsp_Channel_Req_MTCnumber"::float8, "DL_Fail_EDGE_Rate"::float8, "ZTR104B:Call_Drop_Rate_on_SDCCH_Call_Type"::float8, "Call_Drop_no_MR"::float8, "DL_Drop_Congnumber"::float8, "HO_Inc_InterRAT_reqnumber"::float8, "TCH_Assign_Cong_rate"::float8, "HO_Inc_Fail_Rate"::float8, "TCH_Assign_Fail_sp_ver_unav"::float8, "HO_Inc_InterRAT_unsucc"::float8, "A3170A:Number_of_Completed_TCH_Assignments_CSFB_MOC"::float8, "HO_Inc_Unsucc_Rate"::float8, "TSs_Interf_B4"::float8, "A3100K:Assignment_Requests_Signaling_Channel_SDCCH"::float8, "TCH_Drops_cause_UpDown_Level"::float8, "SDCCH_Fail_Nbnumber"::float8, "TCH_Non_Radio_Drops"::float8, "DL_Fail_MSnumber"::float8, "HO_Cmd_DL_Qual"::float8, "DL_Drop_OtherCausenumber"::float8, "SMS_on_SDCCH"::float8, "FERnumber"::float8, "HO_Inc_Reqnumber"::float8, "nsp_Urban_TA_3_R"::float8, "M3020D:Call_Drops_on_SDCCHOther"::float8, "HO_Out_External_Succ_Rate"::float8, "M3020A:Call_Drops_on_SDCCHTA"::float8, "TCH_Assign_Fail_Radio_rate"::float8, "CR3001:Number_of_Initially_Configured_Channels_Static_PDCH"::float8, "HR_Traffic_totalErl"::float8, "CH_Req_MTCnbnumber"::float8, "SDCCH_Drop_RxQual"::float8, "UL_RxLev_avgdBm"::float8, "CH_Req_MOCnbnumber"::float8, "SDCCH_Dropnumber"::float8, "A3169A:Failed_Assignments_Um_Cause"::float8, "A3129H:Failed_Assignments_Clear_Commands_Sent_By_MSC"::float8, "TCH_Radio_Drops"::float8, "HO_Out_InterRAT_Req_Nb"::float8, "HO_Inc_InterRAT_succnumber"::float8, "DL_Drop_Abisnumber"::float8, "TCH_Drops_cause_UL_FER"::float8, "UL_RxLevelnumber"::float8, "nsp_CH_Request_CSnumber"::float8, "A3170B:Number_of_Completed_TCH_Assignments_CSFB_MTC"::float8, "A3129F:Failed_Assignments_CIC_Allocated"::float8, "DL_Fail_GPRS_Rate"::float8, "M3020B:Call_Drops_on_SDCCHReceived_Level"::float8, "nsp_Urban_TA_1number"::float8, "SDCCH_Availability"::float8, "Call_Drop_forced_HO"::float8, "SDCCH_Drop_Others"::float8, "Call_Drop_Equip."::float8, "CH_Req_PS"::float8, "SDCCH_Drop_Call_Rate"::float8, "TCH_Drops_cause_UpQual"::float8, "CH_Req_LMU_Reservednbnumber"::float8, "DL_RxLevnumber"::float8, "nsp_Urban_TA_1_R"::float8, "A312Ea:Failed_Assignments_during_Call_Reestablishment_on_the_A_"::float8, "TSs_Interf_B3"::float8, "SDCCH_Drop_TimingAdvance"::float8, "Avg_BTS_Power_Level_NAMR"::float8, "TCH_Drops_cause_Other"::float8, "FR_TraficErl"::float8, "Avg_MS_Power_Level"::float8, "HO_Outgoing_Requestsnumber"::float8, "A3129G:Failed_Assignments_A_Interface_Failure"::float8, "CH_Req_LAU"::float8, "nsp_Urban_TA_5_R"::float8, "HO_Inc_Unsuccessnumber"::float8, "AS3240A:Average_MS_Power_Level_of_AMR_Call"::float8 from "PM"."VM_gcell_evolution_hourly_BSC_recovered")
It says "column is of type double but expression is of type text" so what's really happening is that it's trying to insert one of the expressions where you cast to ::text into a column that is of type double. If the problem was converting from text to double, you'd get a different message. Besides, the SELECT worked fine, which means it didn't encounter any text data that it couldn't convert to double. Since you don't specify the target table columns in your INSERT, and you have so many of them, most likely you missed a column or got the order wrong. Honestly if the table has 270 columns and they have the same name in the source and destination tables, you should really generate the query using something like python from a list of columns, that will be faster than proofreading the 270 lines...