Below you will find pages that utilize the taxonomy term “Postgres”
JSON datatype in postgreSQL
Introduction
PostgreSQL provides us with a datatype to store JSON data. This datatype can be helpful in lots of situations giving us a way to store some dynamic data.
Further PostgreSQL provides us with two types for storing JSON data
- json
- jsonb
They both take almost identical set of inputs but the major difference is that in the efficiency.
The json
data type stores the exact copy of the input text which the processing functions must reparse
on each execution.
On the other hand jsonb
data is stored in the decompressed binary format which makes it slightly slower
to input due to the added overhead of conversion, but significantly faster to process since no reparsing is needed.
Using Constants in PostgreSQL queries
Introduction
Imagine we have a long query which has a lots of conditions, and many of the conditions has some kind of comparisions with literals instead of some other record value.
Example:
SELECT * FROM users u where (u.name='some name' or u.age=12 or u.email='qwe@qwe.qwe');
For example sake we are taking the name, age and email as constants.
Imagine these literal values used multiple times in the query. We will have very untidy query.