Re: Aggregate Network Address functions?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: April L <april(at)i-netco(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Aggregate Network Address functions?
Date: 2002-04-18 17:03:58
Message-ID: 13506.1019149438@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

April L <april(at)i-netco(dot)com> writes:
> I tried

> SELECT MAX(masklen(ip))
> FROM nlist
> WHERE ip >> '208.253.55.61';

> That returns an integer of the largest mask length... such as /24 or /32.

> How would I get the other fields associated with the record that has the
> largest mask length?

> Or, in general, how does one find the record with the largest value in a
> column and get all the columns from that particular record?

The usual recommendation is

SELECT * FROM nlist
WHERE ip >> '208.253.55.61'
ORDER BY masklen(ip) DESC
LIMIT 1;

I'm not sure what people do in databases that don't have LIMIT; there
doesn't seem to be any nice solution in bog-standard SQL.

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message samsom, debra 2002-04-18 17:36:03 Re: Multiple Primary Keys
Previous Message April L 2002-04-18 16:46:54 Aggregate Network Address functions?