From eb81adfcc025585079f31ae2c0a1cc4309a9451a Mon Sep 17 00:00:00 2001 From: Aryan Ramesh Jain <138214350+jainaryan04@users.noreply.github.com> Date: Tue, 5 Nov 2024 23:31:24 +0530 Subject: [PATCH 1/6] handling json data in sql #1863 --- docs/languages/SQL/sql-25.md | 87 ++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 docs/languages/SQL/sql-25.md diff --git a/docs/languages/SQL/sql-25.md b/docs/languages/SQL/sql-25.md new file mode 100644 index 000000000..5440d01f8 --- /dev/null +++ b/docs/languages/SQL/sql-25.md @@ -0,0 +1,87 @@ +--- +id: SQL-JSON-Data +sidebar_position: 25 +title: "JSON Data in SQL" +sidebar_label: "JSON Data in SQL" +description: "Handling JSON Data Within SQL." +tags: [sql, dbms, database, json, data, backend] +--- + +## Introduction +With the growing use of JSON (JavaScript Object Notation) for data exchange, many modern databases have introduced native support for JSON data types. This enables efficient querying and manipulation of JSON data directly within SQL. + +## JSON Data Type +Many SQL databases, including MySQL, PostgreSQL, and SQL Server, support a `JSON` data type, allowing structured data to be stored in a single column. + +### Benefits: +- **Structured Storage**: Store hierarchical data. +- **Efficient Access**: Query and manipulate JSON data using SQL. +- **Flexibility**: Schema-less data storage. + +## Storing JSON in SQL +You can store JSON data in a `JSON` or `TEXT` column depending on the database. + +### Example: +```sql +CREATE TABLE users ( + id INT PRIMARY KEY, + details JSON +); + +INSERT INTO users (id, details) VALUES +(1, '{"name": "Alice", "age": 30, "email": "alice@example.com"}'); +``` + +## Querying JSON Data +SQL provides functions to query and extract values from JSON data. + +### MySQL: +```sql +SELECT details->'$.name' AS name FROM users; +``` + +### PostgreSQL: +```sql +SELECT details->>'name' AS name FROM users; +``` + +### SQL Server: +```sql +SELECT JSON_VALUE(details, '$.name') AS name FROM users; +``` + +## Modifying JSON Data +Use JSON functions to update, add, or remove JSON elements. + +### MySQL Example: +```sql +UPDATE users SET details = JSON_SET(details, '$.age', 31) WHERE id = 1; +``` + +### PostgreSQL Example: +```sql +UPDATE users SET details = jsonb_set(details, '{age}', '31', false) WHERE id = 1; +``` + +## Indexing JSON Data +JSON fields can be indexed to improve query performance. + +### MySQL: +```sql +ALTER TABLE users ADD INDEX idx_name ((details->'$.name')); +``` + +### PostgreSQL: +```sql +CREATE INDEX idx_name ON users ((details->>'name')); +``` + +## Use Cases +- **Flexible Data Models**: Store varying data structures. +- **API Integration**: Easily handle JSON responses. +- **Data Analysis**: Aggregate and filter nested data. + +## Conclusion +Handling JSON data within SQL combines the flexibility of JSON with the robustness of SQL databases. By leveraging native JSON support, developers can efficiently store, query, and manipulate JSON data, optimizing database operations for modern applications. + +This file provides a comprehensive guide on handling JSON data within SQL, covering essential operations and examples for different databases. From 827d906b439d17859730a62be9f1a16b78f5ec9c Mon Sep 17 00:00:00 2001 From: ajay-dhangar <99037494+ajay-dhangar@users.noreply.github.com> Date: Tue, 5 Nov 2024 18:01:39 +0000 Subject: [PATCH 2/6] update contributors list in README --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d6fd89ffb..a1650a53d 100644 --- a/README.md +++ b/README.md @@ -450,6 +450,13 @@ Thanks to these amazing people who have contributed to the **Algo** project: Kundan Rajoria + + + PavanTeja2005 +
+ PavanTeja2005 +
+ tanishqkolhatkar93 @@ -463,13 +470,6 @@ Thanks to these amazing people who have contributed to the **Algo** project:
riddhi
- - - - PavanTeja2005 -
- PavanTeja2005 -
@@ -481,17 +481,17 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - Mansi07sharma + + jainaryan04
- Mansi07sharma + Aryan Ramesh Jain
- - jainaryan04 + + Mansi07sharma
- Aryan Ramesh Jain + Mansi07sharma
From 7d37657033e5e8701b075e00a878e8cc789ff8aa Mon Sep 17 00:00:00 2001 From: ajay-dhangar <99037494+ajay-dhangar@users.noreply.github.com> Date: Wed, 6 Nov 2024 17:01:59 +0000 Subject: [PATCH 3/6] update contributors list in README --- README.md | 264 ++++++++++++++++++++++++++---------------------------- 1 file changed, 128 insertions(+), 136 deletions(-) diff --git a/README.md b/README.md index 5f894c2bd..b2fc7ab44 100644 --- a/README.md +++ b/README.md @@ -187,17 +187,17 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - yashksaini-coder + + KapuluruBhuvaneswariVspdbct
- Yash Kumar Saini + Bhuvaneswari Kapuluru
- - KapuluruBhuvaneswariVspdbct + + yashksaini-coder
- Bhuvaneswari Kapuluru + Yash Kumar Saini
@@ -268,17 +268,17 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - nishant4500 + + kjl98
- Nishant Dwivedi + Kajal Ahirwar
- - kjl98 + + nishant4500
- Kajal Ahirwar + Nishant Dwivedi
@@ -333,26 +333,26 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - AE-Hertz + + PrAyAg9
- Abhinandan + Prayag Thakur
- - PrAyAg9 + + AE-Hertz
- Prayag Thakur + Abhinandan
- - Mahateaa + + Shariq2003
- Mahathi + Shariq
@@ -363,10 +363,10 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - Shariq2003 + + Mahateaa
- Shariq + Mahathi
@@ -407,33 +407,33 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - KashishJuneja101003 + + Abhishek2634
- Kashish Juneja + Abhishek Farshwal
- - Rashigera + + Subashree-selvaraj
- Rashigera + subashree
- - Abhishek2634 + + KashishJuneja101003
- Abhishek Farshwal + Kashish Juneja
- - Subashree-selvaraj + + Rashigera
- subashree + Rashigera
@@ -451,25 +451,17 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - PavanTeja2005 -
- PavanTeja2005 -
- - - - tanishqkolhatkar93 - + + jainaryan04
- PavanTeja2005 + Aryan Ramesh Jain
- - mehul-m-prajapati + + T-Fathima
- Mehul Prajapati + Tatheer Fathima
@@ -489,10 +481,17 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - jainaryan04 + + PavanTeja2005
- Aryan Ramesh Jain + PavanTeja2005 +
+ + + + mehul-m-prajapati +
+ Mehul Prajapati
@@ -510,12 +509,14 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - khurshed07 + + shimmer12
- khurshed Ansari + Srishti Soni
+ + Asmi1108 @@ -523,71 +524,55 @@ Thanks to these amazing people who have contributed to the **Algo** project: Asmi - - - - shimmer12 -
- Srishti Soni -
- - - - LitZeus + + khurshed07
- Tejas Athalye + khurshed Ansari
- - AKSHITHA-CHILUKA + + jvkousthub
- ~Chiluka Akshitha + Kousthub J V
- - Siddhart2004 + + govindumeesala
- SIDDHARTH A + Meesala Govindu
- - T-Fathima + + sriraghavi22
- Tatheer Fathima + sriraghavi22
- - jvkousthub + + AKSHITHA-CHILUKA
- Kousthub J V + ~Chiluka Akshitha
- - sriraghavi22 -
- sriraghavi22 -
- - - - govindumeesala + + LitZeus
- Meesala Govindu + Tejas Athalye
- - AADESHak007 + + Siddhart2004
- Aadesh_Kumar + SIDDHARTH A
@@ -604,6 +589,13 @@ Thanks to these amazing people who have contributed to the **Algo** project: Hamza Mubin + + + AADESHak007 +
+ Aadesh_Kumar +
+ Saaarthak0102 @@ -627,6 +619,20 @@ Thanks to these amazing people who have contributed to the **Algo** project: Aditya Jani + + + karthikyandrapu +
+ Durga Karthik Yandrapu +
+ + + + Bhumika-00 +
+ Bhumika Sharma +
+ AswaniBolisetti @@ -641,13 +647,8 @@ Thanks to these amazing people who have contributed to the **Algo** project: Md Afzal Mir - - - Bhumika-00 -
- Bhumika Sharma -
- + + Jivanjamadar @@ -655,8 +656,6 @@ Thanks to these amazing people who have contributed to the **Algo** project: Jivan - - Lighting-pixel @@ -665,31 +664,24 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - samar12-rad -
- Samarth Vaidya -
- - - - ShudarsanRegmi + + Shantnu-singh
- Shudarsan Regmi + shantnu
- - varshapandiann + + KunikaMakker
- Varsha Pandian + Kunika Makker
- - alo7lika + + samar12-rad
- alolika bhowmik + Samarth Vaidya
@@ -702,24 +694,24 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - KunikaMakker + + alo7lika
- Kunika Makker + alolika bhowmik
- - Shantnu-singh + + varshapandiann
- shantnu + Varsha Pandian
- - Dishaaa-T + + ShudarsanRegmi
- Disha T + Shudarsan Regmi
@@ -729,6 +721,13 @@ Thanks to these amazing people who have contributed to the **Algo** project: Shashmitha V + + + Dishaaa-T +
+ Disha T +
+ purnima2904 @@ -736,6 +735,8 @@ Thanks to these amazing people who have contributed to the **Algo** project: Purnima Gupta + + shamvrueth @@ -743,8 +744,6 @@ Thanks to these amazing people who have contributed to the **Algo** project: shamvrueth - - IRFANSARI @@ -752,13 +751,6 @@ Thanks to these amazing people who have contributed to the **Algo** project: Irfan Ansari - - - karthikyandrapu -
- Durga Karthik Yandrapu -
- AnushkaChouhan25 From e8cad88253d23ac4c593bd3f6c4490b3c9eb3ad4 Mon Sep 17 00:00:00 2001 From: Aryan Ramesh Jain <138214350+jainaryan04@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:33:15 +0530 Subject: [PATCH 4/6] update id --- docs/languages/SQL/sql-25.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/languages/SQL/sql-25.md b/docs/languages/SQL/sql-25.md index 5440d01f8..9b252f4d3 100644 --- a/docs/languages/SQL/sql-25.md +++ b/docs/languages/SQL/sql-25.md @@ -1,5 +1,5 @@ --- -id: SQL-JSON-Data +id: sql-json-data sidebar_position: 25 title: "JSON Data in SQL" sidebar_label: "JSON Data in SQL" From a87ffa63053741e8fa78fef49c21a264ee8dab45 Mon Sep 17 00:00:00 2001 From: ajay-dhangar <99037494+ajay-dhangar@users.noreply.github.com> Date: Wed, 6 Nov 2024 17:03:30 +0000 Subject: [PATCH 5/6] update contributors list in README --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index b2fc7ab44..6961956ec 100644 --- a/README.md +++ b/README.md @@ -429,6 +429,13 @@ Thanks to these amazing people who have contributed to the **Algo** project: + + + jainaryan04 +
+ Aryan Ramesh Jain +
+ Rashigera @@ -450,13 +457,6 @@ Thanks to these amazing people who have contributed to the **Algo** project: Kundan Rajoria - - - jainaryan04 -
- Aryan Ramesh Jain -
- T-Fathima @@ -488,17 +488,17 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - mehul-m-prajapati + + Mansi07sharma
- Mehul Prajapati + Mansi07sharma
- - Mansi07sharma + + mehul-m-prajapati
- Mansi07sharma + Mehul Prajapati
From cad81f0c8a4c7c3b5457882a2cb61382484d4df7 Mon Sep 17 00:00:00 2001 From: ajay-dhangar <99037494+ajay-dhangar@users.noreply.github.com> Date: Thu, 7 Nov 2024 03:01:07 +0000 Subject: [PATCH 6/6] update contributors list in README --- README.md | 120 +++++++++++++++++++++++++++--------------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 5befbc18e..a01737913 100644 --- a/README.md +++ b/README.md @@ -333,19 +333,19 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - PrAyAg9 + + Shariq2003
- Prayag Thakur + Shariq
- - AE-Hertz + + MithanshuHedau
- Abhinandan + Mithanshu Hedau
@@ -356,17 +356,24 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - MithanshuHedau + + AE-Hertz
- Mithanshu Hedau + Abhinandan
- - Shariq2003 + + PrAyAg9
- Shariq + Prayag Thakur +
+ + + + shriyadindi +
+ Shriya Dindi
@@ -376,6 +383,8 @@ Thanks to these amazing people who have contributed to the **Algo** project: Mugundh J B + + pratheekv39 @@ -383,8 +392,6 @@ Thanks to these amazing people who have contributed to the **Algo** project: V Pratheek - - monishkumardvs @@ -392,13 +399,6 @@ Thanks to these amazing people who have contributed to the **Algo** project: Dvs monish kumar - - - shriyadindi -
- Shriya Dindi -
- aditiverma-21 @@ -407,40 +407,54 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - Alpha1zln + + Subashree-selvaraj
- SHREYAS YADUVANSHI + subashree
- - Rashigera + + Abhishek2634
- Rashigera + Abhishek Farshwal
- - Subashree-selvaraj + + KashishJuneja101003
- subashree + Kashish Juneja
- - Abhishek2634 + + jainaryan04
- Abhishek Farshwal + Aryan Ramesh Jain
- - KashishJuneja101003 + + Alpha1zln
- Kashish Juneja + SHREYAS YADUVANSHI +
+ + + + Rashigera +
+ Rashigera +
+ + + + Riddhi12349 +
+ riddhi
@@ -457,6 +471,8 @@ Thanks to these amazing people who have contributed to the **Algo** project: Tatheer Fathima + + Mansi07sharma @@ -465,14 +481,12 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - Riddhi12349 + + mehul-m-prajapati
- riddhi + Mehul Prajapati
- - tanishqkolhatkar93 @@ -487,13 +501,6 @@ Thanks to these amazing people who have contributed to the **Algo** project: PavanTeja2005 - - - mehul-m-prajapati -
- Mehul Prajapati -
- sarthaxtic @@ -502,27 +509,20 @@ Thanks to these amazing people who have contributed to the **Algo** project: - - jainaryan04 + + shimmer12
- Aryan Ramesh Jain + Srishti Soni
+ + Asmi1108
Asmi
- - - - - - shimmer12 -
- Srishti Soni -