

Counting and Grouping JSON Data in PostgreSQL Using FILTER
#Postgres jsonb query how to#
I’m going to use JetBrains DataGrip to connect, and I documented how to do this over on this post. You can then spin this up with docker-compose up. ( 'CAT001', '') Code language: JavaScript ( javascript ) Insert into some_form_data (category_id, submission_response) Here’s the corresponding init.sql file: create table some_form_data ( This allows you to run any SQL scripts in that file when the container is started up, which is very useful for initialising the database schema and loading our demo data. init.sql” to the container directory “ /docker-entrypoint-initdb.d/init.sql“. The volumes section maps the local file “. The environment variables should hopefully be self explanatory, but they are defined by the official postgres docker image, and I am using the explicit config above to override them to my own values. This allows you to access the database from your PC. The service exposes port 5495 on the host machine (your local machine), which is mapped to the default Postgres port 5432 in the container. The service runs a Postgres database version 15.2 using the official Postgres Docker image. This docker compose file defines a single service named “db”. These contents go into a docker-compose.yaml file.

"./init.sql:/docker-entrypoint-initdb.d/init.sql" Code language: JavaScript ( javascript ) POSTGRES_PASSWORD: my_top_secret_password

For this I will use docker-compose: version: '3.9' services: I’m going to use Docker to quickly spin up a throwaway Postgres DB. SQL is always harder if you can’t quite articulate in a sentence or two exactly what it is that you’re trying to display.Īnyway, words fail me, so hopefully a code based example will clear it up much more definitively. I’ve horribly explained that, and so you can imagine just how much fun I had writing the query. Today I needed a query that could take some nested JSON data, a column ID, and then create a single row for each of these distinct column ID’s to show some summary numbers of different nested JSON values.
