Posts

Showing posts with the label postgresql

Using JSONB in PostgreSQL

Image
Introduction JSONB , short for JSON Binary , is a data type developed from the JSON data type and supported by PostgreSQL since version 9.2. The key difference between JSON and JSONB lies in how they are stored. JSONB supports binary storage and resolves the limitations of the JSON data type by optimizing the insert process and supporting indexing. If you want to know how to install PostgreSQL and learn some basic knowledge about it, check out this article . Defining a Column The query below will create a table with a column of the JSONB data type, which is very simple: CREATE TABLE table_name ( id int , name text , info jsonb ); Inserting Data To insert data into a table with a JSONB column, enclose the content within single quotes ('') like this: INSERT INTO table_name VALUES ( 1 , 'name' , '{"text": "text value", "boolean_vaule": true, "array_value": [1, 2, 3]}' ); We can also insert into an array of o...

Installing PostgreSQL with Docker

Image
Introduction In this guide, I'm going to walk you through installing PostgreSQL database and pgAdmin using Docker . The big advantage here is it's quick and straightforward. You won't need to go through a long manual installation process (and potentially spend time fixing errors if they arise). Installing Docker If you don't already have Docker installed on your machine, you'll need to do that first. At this step, you'll need to search Google because the installation process depends on the operating system you're using. Typically, installing Docker on Windows is simpler compared to using Ubuntu . Installing PostgreSQL Once Docker is set up, the next step is to install the PostgreSQL image. Here, I'm using postgres:alpine , which is a minimal version of PostgreSQL (it's lightweight and includes all the essential components needed to use PostgreSQL). docker run -- name postgresql - e POSTGRES_USER ={ username } - e POSTGRES_PASSWORD ={ passw...