Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 71701

All versions of PostgreSQL. Add an additional version-specific tag like [postgresql-13] if that context is relevant.

0 votes
1 answer
137 views

Select records and related entity count

Given the following select that will count related entities for every record SELECT MAIN.*, SUB.app_count FROM my_table_view MAIN LEFT JOIN (SELECT MAIN2.p_key, count(DISTI …
Bax's user avatar
  • 303
1 vote
1 answer
2k views

Avoiding duplicates when joining multiple tables

Schema create table computer (computer_id bigserial primary key, computer_name varchar); create table computer_hdd (computer_hdd_id bigserial, computer_id bigint references computer(com …
Bax's user avatar
  • 303
12 votes
3 answers
33k views

How to unnest and GROUP BY elements of a JSON array?

Given the band table, with a json column holding an array : id | people ---+------------- 1 | ['John', 'Thomas'] 2 | ['John', 'James'] 3 | ['James', 'George'] How to list the number of bands eac …
Bax's user avatar
  • 303
7 votes

How to unnest and GROUP BY elements of a JSON array?

Based on @ypercubeᵀᴹ comment I ended up with : SELECT name, count(*) as c FROM band CROSS JOIN LATERAL jsonb_array_elements(people::jsonb) as name GROUP BY name; Just used jsonb_array_elements ins …
Bax's user avatar
  • 303