Thread: last row of table after csv import

last row of table after csv import

From
e-letter
Date:
Readers,

After csv of data, is there a command to navigate to the last row of
data in the database table, after import of csv data? The csv file is
not sorted, so the request is to view the last row after import. Now
after import, the keyboard key 'z' is pressed down until the last row
is shown in the command terminal!

Thanks in advance.

Re: last row of table after csv import

From
Josh Kupershmidt
Date:
On Mon, Oct 17, 2011 at 6:06 PM, e-letter <inpost@gmail.com> wrote:
> After csv of data, is there a command to navigate to the last row of
> data in the database table, after import of csv data? The csv file is
> not sorted, so the request is to view the last row after import. Now
> after import, the keyboard key 'z' is pressed down until the last row
> is shown in the command terminal!

Uh, what interface are you using to talk to PostgreSQL (e.g. pgAdmin,
phpPgAdmin, psql, something else?). If the tool you're using lets you
enter SQL queries, you should be able to enter a SELECT query with
ORDER BY and LIMIT to get the result you need. You will have to figure
out what you mean by "last row", i.e. what column(s) you give to ORDER
BY.

If you're not using psql, you might have to ask on a forum specific to
the interface you're dealing with (this list is fine for questions
about psql).
Josh

Re: last row of table after csv import

From
Henry Drexler
Date:
On Mon, Oct 17, 2011 at 6:06 PM, e-letter <inpost@gmail.com> wrote:
Readers,

After csv of data, is there a command to navigate to the last row of
data in the database table, after import of csv data? The csv file is
not sorted, so the request is to view the last row after import. Now
after import, the keyboard key 'z' is pressed down until the last row
is shown in the command terminal!

Thanks in advance.

 
perhaps first do a 
select 
count(*) from table

then 

select
*
from
table
limit 1 offset (the result of your count(*) -1)

Re: last row of table after csv import

From
e-letter
Date:
On 18/10/2011, Josh Kupershmidt <schmiddy@gmail.com> wrote:
> On Mon, Oct 17, 2011 at 6:06 PM, e-letter <inpost@gmail.com> wrote:
>> After csv of data, is there a command to navigate to the last row of
>> data in the database table, after import of csv data? The csv file is
>> not sorted, so the request is to view the last row after import. Now
>> after import, the keyboard key 'z' is pressed down until the last row
>> is shown in the command terminal!
>
> Uh, what interface are you using to talk to PostgreSQL (e.g. pgAdmin,
> phpPgAdmin, psql, something else?). If the tool you're using lets you
> enter SQL queries, you should be able to enter a SELECT query with
> ORDER BY and LIMIT to get the result you need. You will have to figure
> out what you mean by "last row", i.e. what column(s) you give to ORDER
> BY.
>

No interface, using command terminal to enter sql commands.

The csv file of data is not ordered in any way, so I expect the
command '\copy' to import data into a table without changing the
relative positions of data.

Re: last row of table after csv import

From
Thomas Kellerer
Date:
e-letter, 18.10.2011 14:18:
> No interface, using command terminal to enter sql commands.
>
> The csv file of data is not ordered in any way, so I expect the
> command '\copy' to import data into a table without changing the
> relative positions of data.
>
That is a wrong assumption. There is no inherent order of the rows in a table.

Even straight after an insert the order of rows is not guaranteed to be the order in which they were inserted.
The only way to get a defined sort order is to use an ORDER BY clause when SELECTing the data.

Thomas




Re: last row of table after csv import

From
"Daniel Staal"
Date:
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.
---------------------------------------------------------------