How To Create And Insert Data In Postgre Hstore

knoldus data-carbon
Reading Time: 2 minutes

Postgre without a doubt is one of the most popular databases in the market. The reason behind this is PostgreSQL’s speed, security, and robustness. PostgreSQL isn’t just a relational database. PostgreSQL invented many post-relational concepts like in-database functions and user-defined datatypes. Other than that it has many amazing features like Hstore. Now, this blog is for you if you want to know about PostgreSQL Hstore. If you are new to PostgreSQL you can check these blogs to have a basic idea of PostgreSQL https://blog.knoldus.com/lets-get-familiar-with-postgresql-and-its-features/ https://blog.knoldus.com/lets-have-a-look-at-the-postgresql-crud-operation/

Image showing Postgre Hstore

What is Hstore in Postgre?

hstore is a data type in PostgreSQL.It helps in implementing data in the form of key-value pairs for a single value. It is useful in scenarios, such as rows with many attributes that are rarely examined, or semi-structured data. Keys and values are simply text strings.

Syntax: variable_name hstore;


To explain this lets take help of an example

Example :- First, we create an employee table with id as the primary key that identifies the employee, the name as the name of the employee, and detail that stores details of the employee such as department, city, and manager_name. The data type of the detail column is the hstore using the below command:

Creating an hStore column

create table with hstore datatype

Inserting data

firstly we add some data to our employee table using the below command:

Written by 

Divyansh Devrani is a Software Consultant having experience in the Scala Ecosystem. He has worked on technologies like Scala, Akka, Play, and Postgre. He is recognized as a good team player who wants to interact with new technologies. He loves to learn new things His hobbies include listening to muisc, watching movies and anime.

Leave a Reply