Re: get first and last row in one sql as two columns - Mailing list pgsql-general

From Rob Sargent
Subject Re: get first and last row in one sql as two columns
Date
Msg-id 55E785D1.7030300@gmail.com
Whole thread Raw
In response to get first and last row in one sql as two columns  (Tom Smith <tomsmith1989sk@gmail.com>)
Responses Re: get first and last row in one sql as two columns
List pgsql-general
On 09/02/2015 05:14 PM, Tom Smith wrote:
Hi:

I need to get the first and last tow in one sql like below

select first(col1), last(col1) from table order by col1

I saw some posting in wiki with a custom function (or C extention)
to do this.   Is it widely used and reliable?
https://wiki.postgresql.org/wiki/First/last_(aggregate)

I am wondering why these two functions are not part of postgresql built-in
functions as it has many use cases

Thanks
If you're ordering by col1, does
select min(col1), max(col1) from table order by col1

not do the trick;

pgsql-general by date:

Previous
From: Tom Smith
Date:
Subject: get first and last row in one sql as two columns
Next
From: Rob Sargent
Date:
Subject: Re: get first and last row in one sql as two columns