Inline count on a query - Mailing list pgsql-general

From Laura Smith
Subject Inline count on a query
Date
Msg-id F3iOTSNGzv1T_JMTvrmpNewuHtkpyPEiCsjbylqO0bAE1ghq4UDmUi78s_0fMAPOkLuN9mzZQyQfzBKex68XqsO09BCNyQ9DmPySbd7_8F8=@protonmail.ch
Whole thread Raw
Responses Re: Inline count on a query
List pgsql-general
Hi,

Let's say we've got a fairly basic table :

create table networks (
lan_id text not null,
net_id text not null,
port_id text not null
);
create index net_uniq on networks(lan_id,port_id);

The query conundrum I am facing is that I need to add metadata to the output of the query that indicates the count of
portsa given net has on a lan. 

So, for example, given :
insert into networks(lan_id,net_id,port_id) values('L1','N1,'P1');
insert into networks(lan_id,net_id,port_id) values('L1','N1,'P2');

The metadata count would be 1, 2 (because 'N1' has 'P1' and 'P2' on 'L1').

Is there a sensible way to query this without stressing out Postgres too much ?  I'm guessing a CTE of some sort ?

Laura



pgsql-general by date:

Previous
From: Adam Sjøgren
Date:
Subject: Re: Database logins taking longer and longer, showing up as "authentication" in ps(1)
Next
From: "David G. Johnston"
Date:
Subject: Re: Inline count on a query