What is this data type? It's some input data from leetcode - sql

I'm doing some exercises of Databases from LeetCode. I want to test my codes on my laptop using MySQL. I hope to have a easy way to import data.
Here is the input data from LeetCode:\
{"headers":{"insurance":["PID","TIV_2015","TIV_2016","LAT","LON"]},"rows":
{"insurance":[[1,224.17,952.73,32.4,20.2],[2,224.17,900.66,52.4,32.7],
[3,824.61,645.13,72.4,45.2],[4,424.32,323.66,12.4,7.7],
[5,424.32,282.9,12.4,7.7],[6,625.05,243.53,52.5,32.8],
[7,424.32,968.94,72.5,45.3],[8,624.46,714.13,12.5,7.8],
[9,425.49,463.85,32.5,20.3],[10,624.46,776.85,12.4,7.7],
[11,624.46,692.71,72.5,45.3],[12,225.93,933,12.5,7.8],
[13,824.61,786.86,32.6,20.3],[14,824.61,935.34,52.6,32.8]]}}
What is the data type?

This is a JSON string. JSON is a common data interchange format.

Related

Unknown postgis gps data format

A third-party program stores tracking data to the db, but I not understand the format. I know that postgis is working there and this column should contain GPS location(s) and maybe additional data.
Example (db dump as csv):
"Location","DateTime"
"010100000023E37C4023E33C40417F41EF407F4740","2020-05-24 15:33:53+00"
How can I decode Location column data?
This is Well-known binary format.
See PostGIS methods for WKB: ST_AsBinary, ST_GeomFromWKB.
WKT methods: ST_AsText, ST_GeomFromText.
The example in WKT format: POINT(28.887256651392033 46.99416914651966).
For .Net can use Geo, NetTopologySuite.IO.TinyWKB.

Flatten transformation for the json-string column (data flow in ADF)

I copy a csv file with a json-string column to the data flow.
I want to flatten it by the json-string column, but the column is not recognized as a json format.
How do I convert it to json-format column, or do you have other ways to deal with it? Thank you
You could ref my answer here: https://stackoverflow.com/a/65770042/10549281
If you have any other concerns, please feel free to let me know.
HTH.

how do i select certain key/value pair from json field inside a SQL table in SNOWFLAKE

I am currently working on building a dataware house in snowflake for the business that i work for and i have encounter some problems. I used to apply the function Json_value in TSQL for extracting certain key/value pair from json format field inside my original MSSQL DB.
All the other field are in the regular SQL format but there is this one field that i really need that is formated in JSON and i can't seems to exact the key/value pair that i need.
I'm new to SnowSQL and i can't seems to find a way to extract this within a regular query. Does anyone knows a way around my problem ?
* ID /// TYPE /// Name (JSON_FORMAT)/// Amount *
1 5 {En: "lunch, fr: "diner"} 10.00
I would like to extract this line (for exemple) and be able to only retrieve the EN: "lunch" part from my JSON format field.
Thank you !
Almost any time you use JSON in Snowflake, it's advisable to use the VARIANT data type. You can use the parse_json function to convert a string into a variant with JSON.
select
parse_json('{En: "lunch", fr: "diner"}') as VARIANT_COLUMN,
VARIANT_COLUMN:En::string as ENGLISH_WORD;
In this sample, the first column converts your JSON into a variant named VARIANT_COLUMN. The second column uses the variant, extracting the "En" property and casting it to a string data type.
You can define columns as variant and store JSON natively. That's going to improve performance and allow parsing using dot notation in SQL.
For anyone else who also stumbles upon this question:
You can also use JSON_EXTRACT_PATH_TEXT. Here is an example, if you wanted to create a new column called meal.
select json_extract_path_text(Name,'En') as meal from ...

How do I convert this data into a tabular format?

This is the data: https://github.com/sealneaward/nba-movement-data/blob/master/data/01.01.2016.CHA.at.TOR.7z
I am not sure how to convert this data into a dataframe (likely multiple dataframes). Can anyone help me or direct me to a good resource?

Import PostgreSQL dump into SQL Server - data type errors

I have some data which was dumped from a PostgreSQL database (allegedly, using pg_dump) which needs to get imported into SQL Server.
While the data types are ok, I am running into an issue where there seems to be a placeholder for a NULL. I see a backslash followed by an uppercase N in many fields. Below is a snippet of the data, as viewed from within Excel. Left column has a Boolean data type, and the right one has an integer as the data type
Some of these are supposed to be of the Boolean datatype, and having two characters in there is most certainly not going to fly.
Here's what I tried so far:
Import via dirty read - keeping whatever datatypes SSIS decided each field had; to no avail. There were error messages about truncation on all of the boolean fields.
Creating a table for the data based on the correct data types, though this was more fun... I needed to do the same as in the dirty read, as the source would otherwise not load properly. There was also a need to transform the data into the correct data type for insertion into the destination data source; yet, I am getting truncation issues, when it most certainly shouldn't be.
Here is a sample expression in my derived column transformation editor:
(DT_BOOL)REPLACE(observation,"\\N","")
The data type should be Boolean.
Any suggestion would be really helpful!
Thanks!
Since I was unable to circumvent the SSIS rules in order to get my data into my tables without an error, I took the quick-and-dirty approach.
The solution which worked for me was to have the source data read each column as if it were a string, and the destination table had all fields be of the datatype VARCHAR. This destination table will be used as a staging table, once in SS, I can manipulate as needed.
Thank you #cha for your input.