I am trying to extract the Unnest data contained in JSON Arrays that Google Ads sends via BigQuery Data Transfers. Unfortunately, I am getting stuck in the middle.
Original Data in a BigQuery Table:
CreativeId
ResponsiveSearchAdDescriptions
487067671679
[{"assetText":"SearchAds Description Text 1","assetId":12443453594,"pinnedField":"DESCRIPTION_1","assetPerformanceLabel":"PENDING","assetApprovalStatus":"APPROVED"},{"assetText":"SearchAds Description Text 2","assetId":12443453165,"assetPerformanceLabel":"PENDING","assetApprovalStatus":"APPROVED"},{"assetText":"SearchAds Description Text 3","assetId":12443453168,"assetPerformanceLabel":"PENDING","assetApprovalStatus":"APPROVED"},{"assetText":"SearchAds Description Text 4","assetId":12443419160,"assetPerformanceLabel":"PENDING","assetApprovalStatus":"APPROVED"}]
Desired Outcome:
CreativeId
ResponsiveSearchAdDescriptions_assetText
ResponsiveSearchAdDescriptions_assetId
ResponsiveSearchAdDescriptions_pinnedField
ResponsiveSearchAdDescriptions_assetPerformanceLabel
ResponsiveSearchAdDescriptions_assetApprovalStatus
487067671679
SearchAds Description Text 1
12443453594
DESCRIPTION_1
PENDING
APPROVED
487067671679
SearchAds Description Text 2
12443453165
---
PENDING
APPROVED
487067671679
SearchAds Description Text 3
12443453168
---
PENDING
APPROVED
487067671679
SearchAds Description Text 4
12443419160
---
PENDING
APPROVED
This is the query that got me the closest but is still showing JSON.
SELECT
CreativeId,
JSON_QUERY_ARRAY(ResponsiveSearchAdDescriptions) AS Ads
FROM
`priXXXXXX.sandbox.Ad_XXXXXXX`
WHERE
ResponsiveSearchAdDescriptions IS NOT NULL
LIMIT
100
The Query should be able to include this condition ResponsiveSearchAdDescriptions IS NOT NULL
Some ideas?
Use below approach
select Creativeld,
json_extract_scalar(el, '$.assetText') as assetText,
json_extract_scalar(el, '$.assetId') as assetId,
json_extract_scalar(el, '$.pinnedField') as pinnedField,
json_extract_scalar(el, '$.assetPerformanceLabel') as assetPerformanceLabel,
json_extract_scalar(el, '$.assetApprovalStatus') as assetApprovalStatus
from `priXXXXXX.sandbox.Ad_XXXXXXX`,
unnest(json_extract_array(ResponsiveSearchAdDescriptions, '$')) el
if applied to sample data in your question - output is
I have this table:
CID CNAME ADDRESS
------------------
100 ABC ABCD
200 DEF DSDFD
I need to export the data from this table to file in this single row. This is what I want..
100 ABC ABCD 200 DEF DSDFD
I am using SAP HANA database. I have tried multiple options but not able to produce the format I want. Appreciate your help!!
Thank you..
I have a requirement like in my input xml file EMP_ID will come multiple times, now while generating output record, it should come like below:
i/p:
123
123
456
789
456
o/p:
123|1
123|2
456|1
789|1
456|2
Please suggest how can this be implementted?
You can use the generate-id() function.
No example code, because no code was given in the question.
I have a table with the columns
Process Varchar(30)
Last_End_Time Integer format '99:99:99'
By mistake the data got loaded for some of the columns in the following format
Process Last_End_Time
ABC 17:04:30
BCD 2.05:30:20
CDE 3.04:20:50
DEF 15:20:52
The unwanted numbers need to be removed only while selecting the data and not from the table. My output after selecting data from the table should be
Process Last_End_Time
ABC 17:04:30
BCD 05:30:20
CDE 04:20:50
DEF 15:20:52
I am using Teradata Version 14. Please help.
I am running two SQL's on two different databases and comparing the results. I am writing the results to a csv file. Currently I am doing a 1 to 1 comparison of the results such that each element in a row of the result set is a row in the csv file.
table name | source column | source value | target value | difference type | target column
__________________________________________________________________________________________
Table A Column A A001 A001 SAME Column A
Table A Column B A002 B002 Different Column B
These are making the csv files far too long, and I wish to change this output to display each row of the result sets stacked on top of each other like this:
A001 A002 A003
A001 B002 A003
But I am not sure of a good way to indicate which columns would be different (I cannot color code in a csv file). Adding a column to the end which says which columns are different is an option, but I feel like there must be a better way.
I will also take suggestions on other possible ways to format these results.
Not sure what is you final goal.
But first you should include a row_id at begining of each row, also include what db that row is from
Then you may include one aditional character to indicate if they are Equal E- or No Equal N-
Also a final field to indicate if the rows as a whole are Equal or not
rowID DB FieldA FieldB FieldC Equal
1 A E-A001 N-A002 E-A003 NO
1 B E-A001 N-B002 E-A003 NO
And if you import that csv in Excel for example you can filter by column where start with N-