Skip site navigation (1) Skip section navigation (2)

Re: last row of table after csv import

From: "Daniel Staal" <DStaal(at)usa(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: last row of table after csv import
Date: 2011-10-18 13:52:56
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
On Tue, October 18, 2011 7:34 am, Henry Drexler wrote:

> perhaps first do a
> select
> count(*) from table
> then
> select
> *
> from
> table
> limit 1 offset (the result of your count(*) -1)

This would get you a random row of the table.  (Just a different random
row than without the offset.)

Easiest solution would be to add a new field to the table, that is an
increasing counter, and take the highest value of that counter.

But I have to ask: What is the actual problem you are trying to solve? 
There's probably a better solution than getting the 'last row'.

Daniel T. Staal

This email copyright the author.  Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes.  This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.

In response to

pgsql-novice by date

Next:From: Andy HalsallDate: 2011-10-18 16:23:25
Subject: Functions returns to libpq with wrong column split
Previous:From: Thomas KellererDate: 2011-10-18 12:34:00
Subject: Re: last row of table after csv import

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group