EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials PostgreSQL Tutorial PostgreSQL JSON vs JSONNB
Secondary Sidebar
PostgreSQL Tutorial
  • Basic
    • What is PostgreSQL
    • PostgreSQL Features
    • How to Install PostgreSQL
    • PostgreSQL Versions
    • PostgreSQL Architecture
    • PostgreSQL GUI
    • Postgres Command-Line
    • PostgreSQL Variables
    • PostgreSQL Data Types
    • PostgreSQL NOT NULL
    • PostgreSQL Integer
    • PostgreSQL Boolean
    • PostgreSQL BIGINT
    • PostgreSQL NULLIF
    • PostgreSQL Administration
    • PostgreSQL Commands
    • PostgreSQL Operators
    • PostgreSQL IN Operator
    • Postgres like query
    • PostgreSQL encode
    • PostgreSQL Cheat Sheet
    • PostgreSQL List Databases
    • PostgreSQL Rename Database
  • Control Statement
    • PostgreSQL IF Statement
    • PostgreSQL if else
    • PostgreSQL CASE Statement
    • PostgreSQL LOOP
    • PostgreSQL For Loop
    • PostgreSQL While Loop
  • Joins
    • Joins in PostgreSQL
    • PostgreSQL Inner Join
    • PostgreSQL Outer Join
    • LEFT OUTER JOIN in PostgreSQL
    • PostgreSQL FULL OUTER JOIN
    • PostgreSQL LEFT JOIN
    • PostgreSQL Full Join
    • PostgreSQL Cross Join
    • PostgreSQL NATURAL JOIN
    • PostgreSQL UPDATE JOIN
  • Queries
    • PostgreSQL Queries
    • PostgreSQL INSERT INTO
    • PostgreSQL WHERE Clause
    • PostgreSQL WITH Clause
    • PostgreSQL ORDER BY
    • PostgreSQL ORDER BY Random
    • PostgreSQL ORDER BY DESC
    • PostgreSQL GROUP BY
    • PostgreSQL group_concat
    • PostgreSQL HAVING
    • PostgreSQL Recursive Query
  • Advanced
    • PostgreSQL Schema
    • Postgres List Schemas
    • PostgreSQL Drop Schema
    • PostgreSQL VARCHAR
    • Array in PostgreSQL
    • PostgreSQL DDL
    • PostgreSQL List Users
    • Postgres Default User
    • Postgres add user
    • PostgreSQL User Password
    • PostgreSQL log_statement
    • PostgreSQL repository
    • PostgreSQL shared_buffer
    • PostgreSQL String Functions
    • PostgreSQL Compare Strings
    • PostgreSQL Text Search
    • PostgreSQL TEXT
    • PostgreSQL String Array
    • PostgreSQL where in array
    • PostgreSQL Constraints
    • PostgreSQL UNIQUE Constraint
    • PostgreSQL CHECK Constraint
    • PostgreSQL INTERSECT
    • PostgreSQL Like
    • Cursors in PostgreSQL
    • PostgreSQL UNION ALL
    • Indexes in PostgreSQL
    • PostgreSQL Index Types
    • PostgreSQL REINDEX
    • PostgreSQL UNIQUE Index
    • PostgreSQL Clustered Index
    • PostgreSQL DROP INDEX
    • PostgreSQL DISTINCT
    • PostgreSQL FETCH
    • PostgreSQL RAISE EXCEPTION
    • PostgreSQL Auto Increment
    • Sequence in PostgreSQL
    • Wildcards in PostgreSQL
    • PostgreSQL Subquery
    • PostgreSQL Alias
    • PostgreSQL LIMIT
    • PostgreSQL Limit Offset
    • PostgreSQL LAG()
    • PostgreSQL Table
    • Postgres Show Tables
    • PostgreSQL Describe Table
    • PostgreSQL Lock Table
    • PostgreSQL ALTER TABLE
    • Postgres Rename Table
    • PostgreSQL List Tables
    • PostgreSQL TRUNCATE TABLE
    • PostgreSQL Table Partitioning
    • Postgres DROP Table
    • PostgreSQL Functions
    • PostgreSQL Math Functions
    • PostgreSQL Window Functions
    • Aggregate Functions in PostgreSQL
    • PostgreSQL Primary Key
    • Foreign Key in PostgreSQL
    • PostgreSQL Procedures
    • PostgreSQL Stored Procedures
    • PostgreSQL Views
    • PostgreSQL Materialized Views
    • Postgres Create View
    • PostgreSQL Triggers
    • PostgreSQL DROP TRIGGER
    • PostgreSQL Date Functions
    • PostgreSQL TO_DATE()
    • PostgreSQL datediff
    • PostgreSQL Timestamp
    • PostgreSQL CURRENT_TIMESTAMP()
    • PostgreSQL Notify
    • PostgreSQL LENGTH()
    • PostgreSQL blob
    • PostgreSQL Median
    • PostgreSQL kill query
    • PostgreSQL Formatter
    • PostgreSQL RANK()
    • PostgreSQL Select
    • PostgreSQL Average
    • PostgreSQL DATE_PART()
    • PostgreSQL EXECUTE
    • PostgreSQL COALESCE
    • PostgreSQL EXTRACT()
    • PostgreSQL Sort
    • PostgreSQL TO_CHAR
    • PostgreSQL Interval
    • PostgreSQL Number Types
    • PostgreSQL ROW_NUMBER
    • Alter Column in PostgreSQL
    • PostgreSQL Identity Column
    • PostgreSQL SPLIT_PART()
    • PostgreSQL CONCAT()
    • PostgreSQL replace
    • PostgreSQL TRIM()
    • PostgreSQL MAX
    • PostgreSQL DELETE
    • PostgreSQL Float
    • PostgreSQL OID
    • PostgreSQL log
    • PostgreSQL REGEXP_MATCHES()
    • PostgreSQL MD5 
    • PostgreSQL NOW()
    • PostgreSQL RANDOM
    • PostgreSQL round
    • PostgreSQL Trunc()
    • PostgreSQL TIME
    • PostgreSQL IS NULL
    • PostgreSQL CURRENT_TIME
    • PostgreSQL MOD()
    • Postgresql Count
    • PostgreSQL Datetime
    • PostgreSQL MIN()
    • PostgreSQL age()
    • PostgreSQL enum
    • PostgreSQL OR
    • PostgreSQL Wal
    • PostgreSQL NOT IN
    • PostgreSQL SET
    • PostgreSQL Current Date
    • PostgreSQL Compare Date
    • PostgreSQL SERIAL
    • PostgreSQL UUID
    • PostgreSQL Merge
    • PostgreSQL Database
    • PostgreSQL Clone Database
    • PostgreSQL Copy Database
    • PostgreSQL Show Databases
    • PostgreSQL Restore Database
    • PostgreSQL DROP DATABASE
    • PostgreSQL ALTER DATABASE
    • Postgres DROP Database
    • Postgres Dump Database
    • PostgreSQL OFFSET
    • PostgreSQL GRANT
    • PostgreSQL COMMIT
    • PostgreSQL ROLLUP
    • PostgreSQL JSON
    • EXPLAIN ANALYZE in PostgreSQL
    • PostgreSQL Temporary Table
    • PostgreSQL Show Tables
    • PostgreSQL cluster
    • PostgreSQL Replication
    • PostgreSQL Logical Replication
    • PostgreSQL flush privileges
    • PostgreSQL Tablespaces
    • CAST in PostgreSQL
    • PostgreSQL CTE
    • hstore in PostgreSQL
    • PostgreSQL Encryption
    • PostgreSQL DECODE()
    • PostgreSQL Vacuum
    • PostgreSQL EXCLUDE
    • Postgres Change Password
    • Postgres Delete Cascade
    • PostgreSQL EXCEPT
    • PostgreSQL Roles
    • PostgreSQL Link
    • PostgreSQL Partition
    • PostgreSQL column does not exist
    • PostgreSQL Log Queries
    • PostgreSQL escape single quote
    • PostgreSQL Query Optimization
    • PostgreSQL Character Varying
    • PostgreSQL Transaction
    • PostgreSQL Extensions
    • PostgreSQL Import CSV
    • PostgreSQL Client
    • PostgreSQL caching
    • PostgreSQL Incremental Backup
    • PostgreSQL JSON vs JSONNB
    • PostgreSQL JDBC Driver
    • PostgreSQL Interview Questions

PostgreSQL JSON vs JSONNB

PostgreSQL-JSON-vs-JSONNB

Introduction to PostgreSQL JSON vs JSONNB

PostgreSQL JSON where JSON stands for ‘Javascript Object Notation’ is a data type of JSON in PostgreSQL which is used to store the data as text with the values stored according to the JSON rules. It basically does not perform any extra processing, instead copies the data similar to the JSON input text, and the processing function is reparsed in every execution in the case of JSON.

PostgreSQL jsonb where jsonb stands for ‘Javascript Object Notation Binary’ is a data type of JSON in PostgreSQL which is used to store the data in the binary format. JSON data is first converted and then stored, so the input of data is somewhat slower than JSON but the processing speed in binary form is much higher so the overall efficiency is excellent in the case of JSON data type.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Head to Head Comparison Between PostgreSQL JSON vs JSONNB (Infographics)

Below are the top 9 differences between PostgreSQL JSON vs JSONNB:

DocumentDB-vs-MongoDB-info

Comparison Table of PostgreSQL JSON vs JSONNB

Below given is the comparison table showing the head to head comparison between JSON and jsonb in PostgreSQL:

S.No.

PostgreSQL json

PostgreSQL jsonb

1 JSON data type stores the exact copy of input text in JSON. Jsonb stores the data as binary code. Basically, it stores the data in binary form which is not an ASCII/ UTF-8 string.
2 Json preserves the original formatting like the whitespaces as well as the ordering of keys. Jsonb does not preserve the original formatting of text like the whitespaces and the ordering of keys.
3 Json processes input faster than jsonb as there is no conversion involved in this. Jsonb converts the JSON data into the binary form so it has slightly slower input due to the binary conversion overhead.
4 There is no change in the Schema design while working with JSON. All the entities, attributes, values remain the same. Schema designs are comparatively easier than Json as it replaces the entity- attribute value with jsonb blob columns which are easier to query.
5 JSON data does not take much disk space as the JSON data is stored as it is. More disk space is required for jsonb data as compared to JSON data type.
6 Processing function needs to be reparsed in each execution when the input text is in JSON data type. In the case of jsonb, it is comparatively faster to process the data as no reparsing is needed.
7 JSON does not support indexing, unlike jsonb. Jsonb supports indexing to search for the keys or key/ value pairs which is a great advantage at a bigger database jsonb documents.
8 In JSON, if there exists more than one key for the given value, all the key/value pairs are preserved. Jsonb does not preserve duplicate object keys. In case of a duplicate, only the last key/value pair is preserved.
9 Unicode escapes are allowed in the JSON input function regardless of the data encoding. It only checks for syntactic errors. The input function of jsonb is stricter than the JSON as it does not allow the unicode escapes for non-ASCII characters if the database encoding of UTF8 is not set.

Key Differences of PostgreSQL JSON vs JSONNB

Some of the key differences between JSON and jsonb explaining the detailed differences between the two are given below:

1. One simple difference between JSON and jsonb data type is that JSON stores the exact copy of the data represented/ inputted in the JSON format to the user whereas jsonb stores the data in the binary format which means that the input data is first processed and then stored in the binary form.

2. If we talk about the ingesting speed and processing speed, it is obvious that the ingesting data using jsonb would be somewhat slower as the data is stored in the binary format (so it will be processed first before getting stored) but the further processing of jsonb data is quite faster as compared to JSON. So in case when there is a need only to ingest too much data, JSON data type would work great.

3. Besides the efficiency of data performance, Jsonb also provides the benefit of GIN (Generalised Inverted Index). It allows the testing of Containment, which checks whether one document is contained in another document or not with the help of @> operator. It returns the result as true or false. Another feature is the provision of Existence Operator in jsonb which checks the existence of top-level keys in JSONB. It is an important feature provided by jsonb and cannot be done using JSON.

4. One of the important improvements of jsonb over JSON is that it allows the indexing of JSON data which is quite helpful in retrieving speedy and correct results especially in the case of aggregate functions when there are millions and trillions of data in the database.

5. jsonb does not store the duplicate key/ value pairs which can be good or bad depending on the requirement of the user. Unlike JSON which stores all the key/ value pairs, it only stores the last key/value pairs.

6. One major drawback of using the jsonb in PostgreSQL is that PostgreSQL does not maintain the statistics while using the jsonb columns. Generally, proper statistics are maintained for each table by PostgreSQL like the distinct values seen, most common values, NULL values, histograms of the distributions. Using the above data, the query planner in PostgreSQL makes the statistics of which plan will provide the best results. But for the jsonb columns, no statistics are stored which results in no planning and ultimately poor results.

7. One another problem encountered with the JSON data type is that at last jsonb results in larger storage footprints as compared to JSON because the key names in JSON are not deduplicated in the case of jsonb storage. Moreover, jsonb encoding of input text has a bit overhead as it does not parse the JSON in order to retrieve a particular field. So the database stores the key/ value pair for each row which increases the database size. If the key appears frequently in the jsonb blobs, one solution to the problem is to store the key as a column in the table.

Conclusion

Above description clearly explains what the JSON and jsonb data type is and how they work in PostgreSQL. As both the JSON and jsonb are used to store the data in their respective purpose, so while working with PostgreSQL, it is important for the programmer to understand the difference between the two and use them accordingly.

Recommended Articles

This is a guide to PostgreSQL JSON vs JSONNB. Here we discuss the PostgreSQL JSON vs JSONNB key differences with infographics and comparison table. You may also have a look at the following articles to learn more –

  1. PostgreSQL vs SQLite
  2. PostgreSQL vs MariaDB
  3. SQL Server vs PostgreSQL
  4. MongoDB vs PostgreSQL
Popular Course in this category
PostgreSQL Course (2 Courses, 1 Project)
  2 Online Courses |  1 Hands-on Project |  7+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more