Thanks in advance for any help. This is killing me! :-)
I have a JSON string that has an object collection nested within it that I need to get a standard SQL result set from. Here is a sample string of the JSON I am working with:
{
"ST": {
"TransactionSetIdentifierCode_01": "835",
"TransactionSetControlNumber_02": "1740",
"ImplementationConventionPreference_03": null
},
"BPR_FinancialInformation": {
"TransactionHandlingCode_01": "I",
"TotalPremiumPaymentAmount_02": "45.75",
"CreditorDebitFlagCode_03": "C",
"PaymentMethodCode_04": "ACH",
"PaymentFormatCode_05": "CCP",
"DepositoryFinancialInstitutionDFIIdentificationNumberQualifier_06": "01",
"OriginatingDepositoryFinancialInstitutionDFIIdentifier_07": "111",
"AccountNumberQualifier_08": "DA",
"SenderBankAccountNumber_09": "33",
"PayerIdentifier_10": "1234567890",
"OriginatingCompanySupplementalCode_11": null,
"DepositoryFinancialInstitutionDFIIdentificationNumberQualifier_12": "01",
"ReceivingDepositoryFinancialInstitutionDFIIdentifier_13": "111",
"AccountNumberQualifier_14": "DA",
"ReceiverBankAccountNumber_15": "22",
"CheckIssueorEFTEffectiveDate_16": "20100101",
"BusinessFunctionCode_17": null,
"DFIIDNumberQualifier_18": null,
"DFIIdentificationNumber_19": null,
"AccountNumberQualifier_20": null,
"AccountNumber_21": null
},
"TRN_ReassociationTraceNumber": {
"TraceTypeCode_01": "1",
"CurrentTransactionTraceNumber_02": "10100000000",
"OriginatingCompanyIdentifier_03": "1000000000",
"ReferenceIdentification_04": null
},
"CUR_ForeignCurrencyInformation": null,
"AllREF": {
"REF_ReceiverIdentification": {
"ReferenceIdentificationQualifier_01": "EV",
"MemberGrouporPolicyNumber_02": "ETIN",
"Description_03": null,
"ReferenceIdentifier_04": null
},
"REF_VersionIdentification": null
},
"DTM_ProductionDate": {
"DateTimeQualifier_01": "405",
"Date_02": "20100101",
"Time_03": null,
"TimeCode_04": null,
"DateTimePeriodFormatQualifier_05": null,
"DateTimePeriod_06": null
},
"AllN1": {
"Loop1000A": {
"N1_PayerIdentification": {
"EntityIdentifierCode_01": "PR",
"PremiumPayerName_02": "NYSDOH",
"IdentificationCodeQualifier_03": null,
"IntermediaryBankIdentifier_04": null,
"EntityRelationshipCode_05": null,
"EntityIdentifierCode_06": null
},
"N3_PayerAddress": {
"ResponseContactAddressLine_01": "OFFICE OF HEALTH INSURANCE PROGRAMS",
"ResponseContactAddressLine_02": "CORNING TOWER, EMPIRE STATE PLAZA"
},
"N4_PayerCity_State_ZIPCode": {
"AdditionalPatientInformationContactCityName_01": "ALBANY",
"AdditionalPatientInformationContactStateCode_02": "NY",
"AdditionalPatientInformationContactPostalZoneorZIPCode_03": "122370080",
"CountryCode_04": null,
"LocationQualifier_05": null,
"LocationIdentifier_06": null,
"CountrySubdivisionCode_07": null
},
"REF_AdditionalPayerIdentification": null,
"AllPER": {
"PER_PayerBusinessContactInformation": null,
"PER_PayerTechnicalContactInformation": [
{
"ContactFunctionCode_01": "BL",
"ResponseContactName_02": "PROVIDER SERVICES",
"CommunicationNumberQualifier_03": "TE",
"ResponseContactCommunicationNumber_04": "8003439000",
"CommunicationNumberQualifier_05": "UR",
"ResponseContactCommunicationNumber_06": "www.emedny.org",
"CommunicationNumberQualifier_07": null,
"ResponseContactCommunicationNumber_08": null,
"ContactInquiryReference_09": null
}
],
"PER_PayerWEBSite": null
}
},
"Loop1000B": {
"N1_PayeeIdentification": {
"EntityIdentifierCode_01": "PE",
"PremiumPayerName_02": "MAJOR MEDICAL PROVIDER",
"IdentificationCodeQualifier_03": "XX",
"IntermediaryBankIdentifier_04": "9999999995",
"EntityRelationshipCode_05": null,
"EntityIdentifierCode_06": null
},
"N3_PayeeAddress": null,
"N4_PayeeCity_State_ZIPCode": null,
"REF_PayeeAdditionalIdentification": [
{
"ReferenceIdentificationQualifier_01": "TJ",
"MemberGrouporPolicyNumber_02": "000000000",
"Description_03": null,
"ReferenceIdentifier_04": null
}
],
"RDM_RemittanceDeliveryMethod": null
}
},
"Loop2000": [
{
"LX_HeaderNumber": {
"AssignedNumber_01": "1"
},
"TS3_ProviderSummaryInformation": null,
"TS2_ProviderSupplementalSummaryInformation": null,
"Loop2100": [
{
"CLP_ClaimPaymentInformation": {
"PatientControlNumber_01": "PATIENT ACCOUNT NUMBER",
"ClaimStatusCode_02": "1",
"TotalClaimChargeAmount_03": "34.25",
"ClaimPaymentAmount_04": "34.25",
"PatientResponsibilityAmount_05": null,
"ClaimFilingIndicatorCode_06": "MC",
"PayerClaimControlNumber_07": "1000210000000030",
"FacilityTypeCode_08": "11",
"ClaimFrequencyCode_09": null,
"PatientStatusCode_10": null,
"DiagnosisRelatedGroupDRGCode_11": null,
"DiagnosisRelatedGroupDRGWeight_12": null,
"DischargeFraction_13": null,
"YesNoConditionorResponseCode_14": null
},
"CAS_ClaimsAdjustment": null,
"AllNM1": {
"NM1_PatientName": {
"EntityIdentifierCode_01": "QC",
"EntityTypeQualifier_02": "1",
"ResponseContactLastorOrganizationName_03": "SUBMITTED LAST",
"ResponseContactFirstName_04": "SUBMITTED FIRST",
"ResponseContactMiddleName_05": null,
"NamePrefix_06": null,
"ResponseContactNameSuffix_07": null,
"IdentificationCodeQualifier_08": "MI",
"ResponseContactIdentifier_09": "LL99999L",
"EntityRelationshipCode_10": null,
"EntityIdentifierCode_11": null,
"NameLastorOrganizationName_12": null
},
"NM1_InsuredName": null,
"NM1_CorrectedPatient_InsuredName": {
"EntityIdentifierCode_01": "74",
"EntityTypeQualifier_02": "1",
"ResponseContactLastorOrganizationName_03": "CORRECTED LAST",
"ResponseContactFirstName_04": "CORRECTED FIRST",
"ResponseContactMiddleName_05": null,
"NamePrefix_06": null,
"ResponseContactNameSuffix_07": null,
"IdentificationCodeQualifier_08": null,
"ResponseContactIdentifier_09": null,
"EntityRelationshipCode_10": null,
"EntityIdentifierCode_11": null,
"NameLastorOrganizationName_12": null
},
"NM1_ServiceProviderName": null,
"NM1_CrossoverCarrierName": null,
"NM1_CorrectedPriorityPayerName": null,
"NM1_OtherSubscriberName": null
},
"MIA_InpatientAdjudicationInformation": null,
"MOA_OutpatientAdjudicationInformation": null,
"AllREF": {
"REF_OtherClaimRelatedIdentification": [
{
"ReferenceIdentificationQualifier_01": "EA",
"MemberGrouporPolicyNumber_02": "PATIENT ACCOUNT NUMBER",
"Description_03": null,
"ReferenceIdentifier_04": null
}
],
"REF_RenderingProviderIdentification": null
},
"AllDTM": {
"DTM_StatementFromorToDate": [
{
"DateTimeQualifier_01": "232",
"Date_02": "20100101",
"Time_03": null,
"TimeCode_04": null,
"DateTimePeriodFormatQualifier_05": null,
"DateTimePeriod_06": null
},
{
"DateTimeQualifier_01": "233",
"Date_02": "20100101",
"Time_03": null,
"TimeCode_04": null,
"DateTimePeriodFormatQualifier_05": null,
"DateTimePeriod_06": null
}
],
"DTM_CoverageExpirationDate": null,
"DTM_ClaimReceivedDate": null
},
"PER_ClaimContactInformation": null,
"AMT_ClaimSupplementalInformation": [
{
"AmountQualifierCode_01": "AU",
"TotalClaimChargeAmount_02": "34.25",
"CreditDebitFlagCode_03": null
}
],
"QTY_ClaimSupplementalInformationQuantity": null,
"Loop2110": null
},
{
"CLP_ClaimPaymentInformation": {
"PatientControlNumber_01": "PATIENT ACCOUNT NUMBER",
"ClaimStatusCode_02": "2",
"TotalClaimChargeAmount_03": "34",
"ClaimPaymentAmount_04": "0",
"PatientResponsibilityAmount_05": null,
"ClaimFilingIndicatorCode_06": "MC",
"PayerClaimControlNumber_07": "1000220000000020",
"FacilityTypeCode_08": "11",
"ClaimFrequencyCode_09": null,
"PatientStatusCode_10": null,
"DiagnosisRelatedGroupDRGCode_11": null,
"DiagnosisRelatedGroupDRGWeight_12": null,
"DischargeFraction_13": null,
"YesNoConditionorResponseCode_14": null
},
"CAS_ClaimsAdjustment": null,
"AllNM1": {
"NM1_PatientName": {
"EntityIdentifierCode_01": "QC",
"EntityTypeQualifier_02": "1",
"ResponseContactLastorOrganizationName_03": "SUBMITTED LAST",
"ResponseContactFirstName_04": "SUBMITTED FIRST",
"ResponseContactMiddleName_05": null,
"NamePrefix_06": null,
"ResponseContactNameSuffix_07": null,
"IdentificationCodeQualifier_08": "MI",
"ResponseContactIdentifier_09": "LL88888L",
"EntityRelationshipCode_10": null,
"EntityIdentifierCode_11": null,
"NameLastorOrganizationName_12": null
},
"NM1_InsuredName": null,
"NM1_CorrectedPatient_InsuredName": {
"EntityIdentifierCode_01": "74",
"EntityTypeQualifier_02": "1",
"ResponseContactLastorOrganizationName_03": "CORRECTED LAST",
"ResponseContactFirstName_04": "CORRECTED FIRST",
"ResponseContactMiddleName_05": null,
"NamePrefix_06": null,
"ResponseContactNameSuffix_07": null,
"IdentificationCodeQualifier_08": null,
"ResponseContactIdentifier_09": null,
"EntityRelationshipCode_10": null,
"EntityIdentifierCode_11": null,
"NameLastorOrganizationName_12": null
},
"NM1_ServiceProviderName": null,
"NM1_CrossoverCarrierName": null,
"NM1_CorrectedPriorityPayerName": null,
"NM1_OtherSubscriberName": null
},
"MIA_InpatientAdjudicationInformation": null,
"MOA_OutpatientAdjudicationInformation": null,
"AllREF": {
"REF_OtherClaimRelatedIdentification": [
{
"ReferenceIdentificationQualifier_01": "EA",
"MemberGrouporPolicyNumber_02": "PATIENT ACCOUNT NUMBER",
"Description_03": null,
"ReferenceIdentifier_04": null
}
],
"REF_RenderingProviderIdentification": null
},
"AllDTM": {
"DTM_StatementFromorToDate": [
{
"DateTimeQualifier_01": "232",
"Date_02": "20100101",
"Time_03": null,
"TimeCode_04": null,
"DateTimePeriodFormatQualifier_05": null,
"DateTimePeriod_06": null
},
{
"DateTimeQualifier_01": "233",
"Date_02": "20100101",
"Time_03": null,
"TimeCode_04": null,
"DateTimePeriodFormatQualifier_05": null,
"DateTimePeriod_06": null
}
],
"DTM_CoverageExpirationDate": null,
"DTM_ClaimReceivedDate": null
},
"PER_ClaimContactInformation": null,
"AMT_ClaimSupplementalInformation": null,
"QTY_ClaimSupplementalInformationQuantity": null,
"Loop2110": null
},
{
"CLP_ClaimPaymentInformation": {
"PatientControlNumber_01": "PATIENT ACCOUNT NUMBER",
"ClaimStatusCode_02": "2",
"TotalClaimChargeAmount_03": "34.25",
"ClaimPaymentAmount_04": "11.5",
"PatientResponsibilityAmount_05": null,
"ClaimFilingIndicatorCode_06": "MC",
"PayerClaimControlNumber_07": "1000230000000020",
"FacilityTypeCode_08": "11",
"ClaimFrequencyCode_09": null,
"PatientStatusCode_10": null,
"DiagnosisRelatedGroupDRGCode_11": null,
"DiagnosisRelatedGroupDRGWeight_12": null,
"DischargeFraction_13": null,
"YesNoConditionorResponseCode_14": null
},
"CAS_ClaimsAdjustment": null,
"AllNM1": {
"NM1_PatientName": {
"EntityIdentifierCode_01": "QC",
"EntityTypeQualifier_02": "1",
"ResponseContactLastorOrganizationName_03": "SUBMITTED LAST",
"ResponseContactFirstName_04": "SUBMITTED FIRST",
"ResponseContactMiddleName_05": null,
"NamePrefix_06": null,
"ResponseContactNameSuffix_07": null,
"IdentificationCodeQualifier_08": "MI",
"ResponseContactIdentifier_09": "LL77777L",
"EntityRelationshipCode_10": null,
"EntityIdentifierCode_11": null,
"NameLastorOrganizationName_12": null
},
"NM1_InsuredName": null,
"NM1_CorrectedPatient_InsuredName": {
"EntityIdentifierCode_01": "74",
"EntityTypeQualifier_02": "1",
"ResponseContactLastorOrganizationName_03": "CORRECTED LAST",
"ResponseContactFirstName_04": "CORRECTED FIRST",
"ResponseContactMiddleName_05": null,
"NamePrefix_06": null,
"ResponseContactNameSuffix_07": null,
"IdentificationCodeQualifier_08": null,
"ResponseContactIdentifier_09": null,
"EntityRelationshipCode_10": null,
"EntityIdentifierCode_11": null,
"NameLastorOrganizationName_12": null
},
"NM1_ServiceProviderName": null,
"NM1_CrossoverCarrierName": null,
"NM1_CorrectedPriorityPayerName": null,
"NM1_OtherSubscriberName": null
},
"MIA_InpatientAdjudicationInformation": null,
"MOA_OutpatientAdjudicationInformation": null,
"AllREF": {
"REF_OtherClaimRelatedIdentification": [
{
"ReferenceIdentificationQualifier_01": "EA",
"MemberGrouporPolicyNumber_02": "PATIENT ACCOUNT NUMBER",
"Description_03": null,
"ReferenceIdentifier_04": null
}
],
"REF_RenderingProviderIdentification": null
},
"AllDTM": {
"DTM_StatementFromorToDate": [
{
"DateTimeQualifier_01": "232",
"Date_02": "20100101",
"Time_03": null,
"TimeCode_04": null,
"DateTimePeriodFormatQualifier_05": null,
"DateTimePeriod_06": null
},
{
"DateTimeQualifier_01": "233",
"Date_02": "20100101",
"Time_03": null,
"TimeCode_04": null,
"DateTimePeriodFormatQualifier_05": null,
"DateTimePeriod_06": null
}
],
"DTM_CoverageExpirationDate": null,
"DTM_ClaimReceivedDate": null
},
"PER_ClaimContactInformation": null,
"AMT_ClaimSupplementalInformation": [
{
"AmountQualifierCode_01": "AU",
"TotalClaimChargeAmount_02": "11.5",
"CreditDebitFlagCode_03": null
}
],
"QTY_ClaimSupplementalInformationQuantity": null,
"Loop2110": null
}
]
}
],
"PLB_ProviderAdjustment": null,
"SE": {
"NumberofIncludedSegments_01": "65",
"TransactionSetControlNumber_02": "1740"
},
"ErrorContext": {
"Name": "835",
"ControlNumber": "1740",
"Edition": "005010",
"Release": "X221A1",
"Index": 2,
"ValidatedSegmentsCount": 0,
"Codes": [],
"Errors": [
{
"Name": "SVC",
"Position": 20,
"LoopId": null,
"Value": "SVC*HC:V2020:RB*6*6**1",
"Codes": [
4
],
"Errors": [],
"Message": "Segment SVC*HC:V2020:RB*6 is not allowed in this position. Only the following segments can appear: AMT, QTY, SVC, CLP, LX, PLB, SE"
}
],
"HasErrors": true,
"Message": null
}
}
This string can be pasted into an online JSON parser to visualize the hierarchy more easily (like http://json.parser.online.fr/).
What I am trying to do is use the SQL Server OPENJSON function to get a result set of the 3 sample claims in this JSON string. The claims are nested in $.Loop2000.Loop2100, and the result I am trying to get is:
Patient Account Number ClaimStatusCode TotalClaimChargeAmount
------------------------------------------------------------------------
Patient Account Number 1 34.25
Patient Account Number 2 34.00
Patient Account Number 3 34.00
I can't seem to get the path right in the OPENJSON function to turn this into a result set with 3 rows. I am trying to use something like:
SELECT * FROM OPENJSON(#sJSON, N'$.Loop2000.Loop2100')
WITH (
PatientControlNumber_01 nvarchar(100) '$.CLP_ClaimPaymentInformation.PatientControlNumber_01'
)
Any help would be much appreciated.
One method you could use is a few nested OPNEJSON calls:
SELECT CPI.*
FROM OPENJSON(#JSON, N'$.Loop2000')
WITH (Loop2100 nvarchar(MAX) AS JSON) L2000
CROSS APPLY OPENJSON(L2000.Loop2100)
WITH(CLP_ClaimPaymentInformation nvarchar(MAX) AS JSON) L2100
CROSS APPLY OPENJSON(L2100.CLP_ClaimPaymentInformation)
WITH (PatientControlNumber varchar(100) '$.PatientControlNumber_01',
ClaimStatusCode int '$.ClaimStatusCode_02',
TotalClaimChargeAmount decimal(12,2) '$.TotalClaimChargeAmount_03') CPI;
I am trying to create a view from 3 different tables. I keep getting an error 'Column 2 in UNION DISTINCT has incompatible types: INT64, STRING, STRING at [165:1]'
What am I doing wrong? The line 165:1 where it is flagging is when the next table starts. Is there a better way to merge 3 tables with different columns?
Below is script for the view
SELECT Date,
Active_View_Impressions__AdWords,
Active_View_Measurable_Cost__AdWords,
Active_View_Measurable_Impressions__AdWords,
All_Conv___AdWords,
SPLIT(Campaign__AdWords,'|')[safe_ordinal(1)] as Location,SPLIT(Campaign__AdWords,'|')[safe_ordinal(2)] as Market_Type,
Click_Assisted_Conv___AdWords,
Clicks__AdWords,
Conversions__AdWords,
Cost__AdWords,
Data_Source_id,
Data_Source_type,
Device__AdWords,
Engagements__AdWords,
Impr__Assisted_Conv___AdWords,
Impressions__AdWords,
Interactions__AdWords,
Invalid_Clicks__AdWords,
Network_With_Search_Params__AdWords,
Total_absolute_top_impressions__AdWords,
Total_Position__AdWords,
Total_top_impressions__AdWords,
Video_views__AdWords,
View_through_Conv___AdWords,
Views__AdWords,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
FROM`inbr.Adwords_02.all_funnel_data_view`
UNION DISTINCT
SELECT Date,
Data_Source_id,
Data_Source_type,
Actions__Facebook_Ads,
Amount_Spent__Facebook_Ads,
Attribution_Window__Facebook_Ads,
Buying_Type__Facebook_Ads,
SPLIT(Campaign_Name__Facebook_Ads,'|')[safe_ordinal(1)] as Market,SPLIT(Campaign_Name__Facebook_Ads,'|')[safe_ordinal(2)] as Market_Type,
Campaign_Objective__Facebook_Ads,
Check_ins__Facebook_Ads,
Clicks_all__Facebook_Ads,
Event_Responses__Facebook_Ads,
Impressions__Facebook_Ads,
Link_Clicks__Facebook_Ads,
n_10_Second_Video_Views__Facebook_Ads,
n_3_Second_Video_Views__Facebook_Ads,
Outbound_Clicks__Facebook_Ads,
Page_Engagement__Facebook_Ads,
Page_Likes__Facebook_Ads,
Page_Mentions__Facebook_Ads,
Page_Tab_Views__Facebook_Ads,
Photo_Views__Facebook_Ads,
Post_Comments__Facebook_Ads,
Post_Engagement__Facebook_Ads,
Post_Reactions__Facebook_Ads,
Post_Shares__Facebook_Ads,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
FROM`inbr.Facebook_Ads_02.all_funnel_data_view`
UNION DISTINCT
SELECT CAST(Date AS DATE) Date,
Data_Source_type,
Data_Source_id,
Campaign,
Data_Source,
Data_Source_name,
Data_Source_type_name,
Ad_legacy__AdWords,
Ad_Group_Name__AdWords,
Ad_Type__AdWords,
SPLIT(Campaign__AdWords,'|')[safe_ordinal(1)] as Market,SPLIT(Campaign__AdWords,'|')[safe_ordinal(2)] as Market_Type,
City__AdWords,
Description__AdWords,
Description_Line_1__AdWords,
Description_Line_2__AdWords,
Device__AdWords,
Expanded_Text_Ad_Description_2__AdWords,
Expanded_Text_Ad_Headline_3__AdWords,
Headline_1__AdWords,
Headline_2__AdWords,
KeywordPlacement__AdWords,
Metro__AdWords,
Network__AdWords,
Network_With_Search_Params__AdWords,
Quality_Score__AdWords,
Region__AdWords,
Clicks__AdWords,
Cost__AdWords,
Engagements__AdWords,
Impressions__AdWords,
Interactions__AdWords,
Invalid_Clicks__AdWords,
Total_absolute_top_impressions__AdWords,
Total_Position__AdWords,
Total_top_impressions__AdWords,
Video_views__AdWords,
Views__AdWords,
Video_impressions__AdWords,
Views_100__AdWords,
Active_View_Impressions__AdWords,
Active_View_Measurable_Cost__AdWords,
Active_View_Measurable_Impressions__AdWords,
All_Conv___AdWords,
Click_Assisted_Conv___AdWords,
Conversions__AdWords,
Impr__Assisted_Conv___AdWords,
SmileSnap_Button_Click_mo_tid_Med___inbr___AdWords_Keyword__AdWords,
Thank_You_Form_mo_tid_Med___inbr___AdWords_Keyword__AdWords,
View_through_Conv___AdWords,
Ad_Name__Facebook_Ads,
Ad_Set_Name__Facebook_Ads,
Age__Facebook_Ads,
Attribution_Window__Facebook_Ads,
Buying_Type__Facebook_Ads,
Campaign_Name__Facebook_Ads,
Campaign_Objective__Facebook_Ads,
Conversion_Device__Facebook_Ads,
Device_Platform__Facebook_Ads,
DMA_Region__Facebook_Ads,
Impression_Device__Facebook_Ads,
Link__Facebook_Ads,
Placement__Facebook_Ads,
Gender__Facebook_Ads,
Platform__Facebook_Ads,
n_10_Second_Video_Views__Facebook_Ads,
n_3_Second_Video_Views__Facebook_Ads,
n_30_Second_Video_Views__Facebook_Ads,
Video_Plays__Facebook_Ads,
Video_thruplay__Facebook_Ads,
Video_Watches_at_100__Facebook_Ads,
Video_Watches_at_25__Facebook_Ads,
Video_Watches_at_50__Facebook_Ads,
Video_Watches_at_75__Facebook_Ads,
Video_Watches_at_95__Facebook_Ads,
Button_Clicks__Facebook_Ads,
Link_Clicks__Facebook_Ads,
Outbound_Clicks__Facebook_Ads,
Check_ins__Facebook_Ads,
Event_Responses__Facebook_Ads,
Page_Engagement__Facebook_Ads,
Page_Likes__Facebook_Ads,
Page_Mentions__Facebook_Ads,
Page_Tab_Views__Facebook_Ads,
Photo_Views__Facebook_Ads,
Post_Comments__Facebook_Ads,
Post_Engagement__Facebook_Ads,
Post_Reactions__Facebook_Ads,
Post_Shares__Facebook_Ads,
Actions__Facebook_Ads,
Amount_Spent__Facebook_Ads,
Clicks_all__Facebook_Ads,
Impressions__Facebook_Ads,
Thank_You_Form_mo_tid_Med___inbr___Facebook_Conversion__Facebook_Ads,
Thank_You_Form_V2_mo_tid_Med___inbr___Facebook_Conversion__Facebook_Ads,
n_100_In_View_Impressions__Facebook_Ads,
Custom_Events__Facebook_Ads,
Landing_Page_Views__Facebook_Ads,
Leads__Facebook_Ads,
Leads_Form__Facebook_Ads,
Ad_Group_ID__The_Trade,
Ad_Group_Name__The_Trade,
Advertiser_ID__The_Trade,
Advertiser_Name__The_Trade,
Advertiser_Total_Cost__The_Trade,
Partner_Cost__The_Trade_1,
Bids__The_Trade,
Campaign_ID__The_Trade,
Campaign_Name__The_Trade,
Clicks__The_Trade,
Impressions__The_Trade,
Partner_ID__The_Trade,
Site__The_Trade,
City__The_Trade,
Country__The_Trade,
Metro__The_Trade,
Region__The_Trade,
Player_25_Complete__The_Trade,
Player_50_Complete__The_Trade,
Player_75_Complete__The_Trade,
Player_Close__The_Trade,
Player_Collapse__The_Trade,
Player_Completed_Views__The_Trade,
Player_Engaged_Views__The_Trade,
Player_Error__The_Trade,
Player_Expansion__The_Trade,
Player_Full_Screen__The_Trade,
Player_Invitation_Accept__The_Trade,
Player_Mute__The_Trade,
Player_Pause__The_Trade,
Player_Resume__The_Trade,
Player_Rewind__The_Trade,
Player_Skip__The_Trade,
Player_Starts__The_Trade,
Player_Unmute__The_Trade,
Player_Views__The_Trade,
Video_Was_Trackable__The_Trade,
Video_Was_Viewable__The_Trade,
n_01___Click_Conversion__The_Trade,
n_02___Click_Conversion__The_Trade,
n_03___Click_Conversion__The_Trade,
n_04___Click_Conversion__The_Trade,
n_05___Click_Conversion__The_Trade,
n_06___Click_Conversion__The_Trade,
n_01___Time_Weighted_Decay_Conversion__The_Trade,
n_02___Time_Weighted_Decay_Conversion__The_Trade,
n_03___Time_Weighted_Decay_Conversion__The_Trade,
n_04___Time_Weighted_Decay_Conversion__The_Trade,
n_05___Time_Weighted_Decay_Conversion__The_Trade,
n_06___Time_Weighted_Decay_Conversion__The_Trade,
n_01___View_Through_Conversion__The_Trade,
n_02___View_Through_Conversion__The_Trade,
n_03___View_Through_Conversion__The_Trade,
n_04___View_Through_Conversion__The_Trade,
n_05___View_Through_Conversion__The_Trade,
n_06___View_Through_Conversion__The_Trade,
n_01___Conversion_Touch__The_Trade,
n_02___Conversion_Touch__The_Trade,
n_03___Conversion_Touch__The_Trade,
n_04___Conversion_Touch__The_Trade,
n_05___Conversion_Touch__The_Trade,
n_06___Conversion_Touch__The_Trade
FROM`inbr.AX_Trade.AX_Trade` ```
According to error message there are type mismatch for column 2 in three tables. So, I have casted second column of first table as string. Please check now.
SELECT Date,
cast(Active_View_Impressions__AdWords as string),
Active_View_Measurable_Cost__AdWords,
Active_View_Measurable_Impressions__AdWords,
All_Conv___AdWords,
SPLIT(Campaign__AdWords,'|')[safe_ordinal(1)] as Location,SPLIT(Campaign__AdWords,'|')[safe_ordinal(2)] as Market_Type,
Click_Assisted_Conv___AdWords,
Clicks__AdWords,
Conversions__AdWords,
Cost__AdWords,
Data_Source_id,
Data_Source_type,
Device__AdWords,
Engagements__AdWords,
Impr__Assisted_Conv___AdWords,
Impressions__AdWords,
Interactions__AdWords,
Invalid_Clicks__AdWords,
Network_With_Search_Params__AdWords,
Total_absolute_top_impressions__AdWords,
Total_Position__AdWords,
Total_top_impressions__AdWords,
Video_views__AdWords,
View_through_Conv___AdWords,
Views__AdWords,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
FROM`inbr.Adwords_02.all_funnel_data_view`
UNION DISTINCT
SELECT Date,
Data_Source_id,
Data_Source_type,
Actions__Facebook_Ads,
Amount_Spent__Facebook_Ads,
Attribution_Window__Facebook_Ads,
Buying_Type__Facebook_Ads,
SPLIT(Campaign_Name__Facebook_Ads,'|')[safe_ordinal(1)] as Market,SPLIT(Campaign_Name__Facebook_Ads,'|')[safe_ordinal(2)] as Market_Type,
Campaign_Objective__Facebook_Ads,
Check_ins__Facebook_Ads,
Clicks_all__Facebook_Ads,
Event_Responses__Facebook_Ads,
Impressions__Facebook_Ads,
Link_Clicks__Facebook_Ads,
n_10_Second_Video_Views__Facebook_Ads,
n_3_Second_Video_Views__Facebook_Ads,
Outbound_Clicks__Facebook_Ads,
Page_Engagement__Facebook_Ads,
Page_Likes__Facebook_Ads,
Page_Mentions__Facebook_Ads,
Page_Tab_Views__Facebook_Ads,
Photo_Views__Facebook_Ads,
Post_Comments__Facebook_Ads,
Post_Engagement__Facebook_Ads,
Post_Reactions__Facebook_Ads,
Post_Shares__Facebook_Ads,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
FROM`inbr.Facebook_Ads_02.all_funnel_data_view`
UNION DISTINCT
SELECT CAST(Date AS DATE) Date,
Data_Source_type,
Data_Source_id,
Campaign,
Data_Source,
Data_Source_name,
Data_Source_type_name,
Ad_legacy__AdWords,
Ad_Group_Name__AdWords,
Ad_Type__AdWords,
SPLIT(Campaign__AdWords,'|')[safe_ordinal(1)] as Market,SPLIT(Campaign__AdWords,'|')[safe_ordinal(2)] as Market_Type,
City__AdWords,
Description__AdWords,
Description_Line_1__AdWords,
Description_Line_2__AdWords,
Device__AdWords,
Expanded_Text_Ad_Description_2__AdWords,
Expanded_Text_Ad_Headline_3__AdWords,
Headline_1__AdWords,
Headline_2__AdWords,
KeywordPlacement__AdWords,
Metro__AdWords,
Network__AdWords,
Network_With_Search_Params__AdWords,
Quality_Score__AdWords,
Region__AdWords,
Clicks__AdWords,
Cost__AdWords,
Engagements__AdWords,
Impressions__AdWords,
Interactions__AdWords,
Invalid_Clicks__AdWords,
Total_absolute_top_impressions__AdWords,
Total_Position__AdWords,
Total_top_impressions__AdWords,
Video_views__AdWords,
Views__AdWords,
Video_impressions__AdWords,
Views_100__AdWords,
Active_View_Impressions__AdWords,
Active_View_Measurable_Cost__AdWords,
Active_View_Measurable_Impressions__AdWords,
All_Conv___AdWords,
Click_Assisted_Conv___AdWords,
Conversions__AdWords,
Impr__Assisted_Conv___AdWords,
SmileSnap_Button_Click_mo_tid_Med___inbr___AdWords_Keyword__AdWords,
Thank_You_Form_mo_tid_Med___inbr___AdWords_Keyword__AdWords,
View_through_Conv___AdWords,
Ad_Name__Facebook_Ads,
Ad_Set_Name__Facebook_Ads,
Age__Facebook_Ads,
Attribution_Window__Facebook_Ads,
Buying_Type__Facebook_Ads,
Campaign_Name__Facebook_Ads,
Campaign_Objective__Facebook_Ads,
Conversion_Device__Facebook_Ads,
Device_Platform__Facebook_Ads,
DMA_Region__Facebook_Ads,
Impression_Device__Facebook_Ads,
Link__Facebook_Ads,
Placement__Facebook_Ads,
Gender__Facebook_Ads,
Platform__Facebook_Ads,
n_10_Second_Video_Views__Facebook_Ads,
n_3_Second_Video_Views__Facebook_Ads,
n_30_Second_Video_Views__Facebook_Ads,
Video_Plays__Facebook_Ads,
Video_thruplay__Facebook_Ads,
Video_Watches_at_100__Facebook_Ads,
Video_Watches_at_25__Facebook_Ads,
Video_Watches_at_50__Facebook_Ads,
Video_Watches_at_75__Facebook_Ads,
Video_Watches_at_95__Facebook_Ads,
Button_Clicks__Facebook_Ads,
Link_Clicks__Facebook_Ads,
Outbound_Clicks__Facebook_Ads,
Check_ins__Facebook_Ads,
Event_Responses__Facebook_Ads,
Page_Engagement__Facebook_Ads,
Page_Likes__Facebook_Ads,
Page_Mentions__Facebook_Ads,
Page_Tab_Views__Facebook_Ads,
Photo_Views__Facebook_Ads,
Post_Comments__Facebook_Ads,
Post_Engagement__Facebook_Ads,
Post_Reactions__Facebook_Ads,
Post_Shares__Facebook_Ads,
Actions__Facebook_Ads,
Amount_Spent__Facebook_Ads,
Clicks_all__Facebook_Ads,
Impressions__Facebook_Ads,
Thank_You_Form_mo_tid_Med___inbr___Facebook_Conversion__Facebook_Ads,
Thank_You_Form_V2_mo_tid_Med___inbr___Facebook_Conversion__Facebook_Ads,
n_100_In_View_Impressions__Facebook_Ads,
Custom_Events__Facebook_Ads,
Landing_Page_Views__Facebook_Ads,
Leads__Facebook_Ads,
Leads_Form__Facebook_Ads,
Ad_Group_ID__The_Trade,
Ad_Group_Name__The_Trade,
Advertiser_ID__The_Trade,
Advertiser_Name__The_Trade,
Advertiser_Total_Cost__The_Trade,
Partner_Cost__The_Trade_1,
Bids__The_Trade,
Campaign_ID__The_Trade,
Campaign_Name__The_Trade,
Clicks__The_Trade,
Impressions__The_Trade,
Partner_ID__The_Trade,
Site__The_Trade,
City__The_Trade,
Country__The_Trade,
Metro__The_Trade,
Region__The_Trade,
Player_25_Complete__The_Trade,
Player_50_Complete__The_Trade,
Player_75_Complete__The_Trade,
Player_Close__The_Trade,
Player_Collapse__The_Trade,
Player_Completed_Views__The_Trade,
Player_Engaged_Views__The_Trade,
Player_Error__The_Trade,
Player_Expansion__The_Trade,
Player_Full_Screen__The_Trade,
Player_Invitation_Accept__The_Trade,
Player_Mute__The_Trade,
Player_Pause__The_Trade,
Player_Resume__The_Trade,
Player_Rewind__The_Trade,
Player_Skip__The_Trade,
Player_Starts__The_Trade,
Player_Unmute__The_Trade,
Player_Views__The_Trade,
Video_Was_Trackable__The_Trade,
Video_Was_Viewable__The_Trade,
n_01___Click_Conversion__The_Trade,
n_02___Click_Conversion__The_Trade,
n_03___Click_Conversion__The_Trade,
n_04___Click_Conversion__The_Trade,
n_05___Click_Conversion__The_Trade,
n_06___Click_Conversion__The_Trade,
n_01___Time_Weighted_Decay_Conversion__The_Trade,
n_02___Time_Weighted_Decay_Conversion__The_Trade,
n_03___Time_Weighted_Decay_Conversion__The_Trade,
n_04___Time_Weighted_Decay_Conversion__The_Trade,
n_05___Time_Weighted_Decay_Conversion__The_Trade,
n_06___Time_Weighted_Decay_Conversion__The_Trade,
n_01___View_Through_Conversion__The_Trade,
n_02___View_Through_Conversion__The_Trade,
n_03___View_Through_Conversion__The_Trade,
n_04___View_Through_Conversion__The_Trade,
n_05___View_Through_Conversion__The_Trade,
n_06___View_Through_Conversion__The_Trade,
n_01___Conversion_Touch__The_Trade,
n_02___Conversion_Touch__The_Trade,
n_03___Conversion_Touch__The_Trade,
n_04___Conversion_Touch__The_Trade,
n_05___Conversion_Touch__The_Trade,
n_06___Conversion_Touch__The_Trade
FROM`inbr.AX_Trade.AX_Trade
https://www.odoo.com/forum/help-1/question/12-0-enable-features-in-the-res-config-settings-149566
I have created my setting data file as the followings mentioned by Alexander inside the page above:
res_config_data.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="my_config_settings" model="res.config.settings">
<field name="company_id" ref="base.main_company"/>
<field name="group_multi_currency" eval="True"/>
<field name="group_product_variant" eval="True"/>
<field name="group_stock_multi_warehouses" eval="True"/>
<field name="group_stock_multi_locations" eval="True"/>
<!-- Delivery Packages -->
<field name="group_stock_tracking_lot" eval="True" />
<field name="module_stock_picking_batch" eval="True" />
<!-- Display Lots & Serial Numbers: Lots & Serial numbers will appear on the delivery slip -->
<field name="group_lot_on_delivery_slip" eval="True" />
<!-- Multi-Step Routes: Use your own routes and putaway strategies -->
<field name="group_stock_adv_location" eval="True" />
<field name="po_order_approval" eval="True" />
<!-- Quantities billed by vendors -->
<field name="default_purchase_method">purchase</field>
<field name="multi_sales_price" eval="True" />
<!-- Multiple prices per product -->
<field name="multi_sales_price_method">percentage</field>
<field name="group_analytic_tags" eval="True" />
<field name="group_analytic_accounting" eval="True" />
<!-- Set specific billing and shipping addresses -->
<field name="group_sale_delivery_address" eval="True" />
<!-- Consignment -->
<field name="group_stock_tracking_owner" eval="True" />
<!-- Prepayment -->
<field name="prepayment_account_id" ref="my_chart_of_account.my_account_prepayments" />
<!-- Multi-company-->
<field name="group_multi_company" eval="False" />
</record>
<function model="res.config.settings" name="execute">
<value model="res.config.settings"
search="[('id', '=', ref('my_config_settings'))]"/>
</function>
</odoo>
__manifest__.py
'data': [
'data/res_config_data.xml',
],
It works if I apply it once only. But when I try to reinstall this setting module, it will not work.
It somehow fails to recognize what fields are the supported.
2020-06-11 02:26:48,117 52288 WARNING odoo_dev odoo.models: res.config.settings.create() with unknown fields: company_id, default_purchase_method, group_analytic_accounting, group_analytic_tags, group_lot_on_delivery_slip, group_multi_company, group_multi_currency, group_product_variant, group_sale_delivery_address, group_stock_adv_location, group_stock_multi_locations, group_stock_multi_warehouses, group_stock_tracking_lot, group_stock_tracking_owner, module_stock_picking_batch, multi_sales_price, multi_sales_price_method, po_order_approval, prepayment_account_id
Odoo discarded these unrecognized fields and insert the plain object into DB
2020-06-11 02:26:48,118 52288 ERROR odoo_dev odoo.sql_db: bad query: b'INSERT INTO "res_config_settings" ("id", "create_uid", "create_date", "write_uid", "write_date") VALUES (nextval(\'res_config_settings_id_seq\'), 1, (now() at time zone \'UTC\'), 1, (now() at time zone \'UTC\')) RETURNING id'
ERROR: null value in column "company_id" violates not-null constraint
DETAIL: Failing row contains (10, 1, 2020-06-11 02:26:47.302998, 1, 2020-06-11 02:26:47.302998, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null).
psycopg2.IntegrityError: null value in column "company_id" violates not-null constraint
DETAIL: Failing row contains (10, 1, 2020-06-11 02:26:47.302998, 1, 2020-06-11 02:26:47.302998, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null).
When I installed this setting module with a brand new Odoo database, and I go to general setting page, I can see the settings are installed. But when I check res.config.settings and ir.config_parameter tables, I don't see any settings record stored. I want to understand how this setting data file being proceeded and stored in where.
Ok although I still have no idea how settings being saved by Odoo. I managed to fix the update setting error.
The reason why it states res.config.settings.create() with unknown fields is because I was trying to update setting that are belongs to different module. For example group_multi_company is under base_setup. However in my setting module I have not listed base_setup as the dependencies.
After putting all modules for those settings I was trying to set, I can update settings properly. Yes if you do not add these dependencies it is still installable but for the first time only, yet you won't be able to update data later on. So always list all related dependent modules.
# -*- coding: utf-8 -*-
{
'name': "My Odoo Settings",
'description': "My configuration for setup",
'version': '12.0.2',
'author': "Wow Ltd.",
'website': "https://github.com/o.o/odoo-addons",
'summary': "My configuration for setup",
# Here, originally I have set with [] only.
# With these I can now update settings successfully
'depends': ['base_setup', 'sale', 'account', 'purchase', 'stock', 'stock_account', 'sale_management'],
'data': [
'data/settings.xml',
],
'installable': True,
}