get first and last row in one sql as two columns

From: Tom Smith <tomsmith1989sk(at)gmail(dot)com>
To: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: get first and last row in one sql as two columns
Date: 2015-09-02 23:14:40
Message-ID: CAKwSVFEjy_q+gCPAri_q40tFx4ZUiLG6BaY+o9A69HXbH7FCPg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rob Sargent 2015-09-02 23:27:13 Re: get first and last row in one sql as two columns
Previous Message Melvin Davidson 2015-09-02 22:07:52 Re: bdr admin role