pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedthe last row in a table
8+ messages / 8 participants
[nested] [flat]
* the last row in a table
@ 1999-03-09 12:08 hoelc <hoelc@pd.jaring.my>
1999-03-09 15:20 ` Re: [INTERFACES] the last row in a table Thomas G. Lockhart <lockhart@alumni.caltech.edu>
1999-03-09 19:30 ` Re: [INTERFACES] the last row in a table Michael Meskes <meskes@postgresql.org>
1999-03-10 02:32 ` Re: [GENERAL] Re: [INTERFACES] the last row in a table Marcin Grondecki <ojciec@mtl.pl>
1999-03-10 08:42 ` Re: [GENERAL] the last row in a table Oleg Broytmann <phd@sun.med.ru>
0 siblings, 4 replies; 8+ messages in thread
From: hoelc @ 1999-03-09 12:08 UTC (permalink / raw)
To: pgsql-interfaces; +Cc: pgsql-admin@postgreSQL.org; pgsql-general@hub.org
Hello,
I am developing a database with PostgreSQL in Linux, and using ecpg to write the
C program to communicate with the database.
One of my application need to get the data from the last row in a table.
Is there any function or command that can tract which is the last row of data in
a table?
Thank you.
Regards,
lch
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [INTERFACES] the last row in a table
1999-03-09 12:08 the last row in a table hoelc <hoelc@pd.jaring.my>
@ 1999-03-09 15:20 ` Thomas G. Lockhart <lockhart@alumni.caltech.edu>
3 siblings, 0 replies; 8+ messages in thread
From: Thomas G. Lockhart @ 1999-03-09 15:20 UTC (permalink / raw)
To: hoelc@pd.jaring.my; +Cc: pgsql-general@hub.org
> I am developing a database with PostgreSQL in Linux, and using ecpg to
> write the C program to communicate with the database.
> One of my application need to get the data from the last row in a
> table. Is there any function or command that can tract which is the
> last row of data in a table?
SQL is a set-oriented language. One should probably not assign any
significance to a storage order of rows.
It *is* possible to order the results of a query, and then your
first/last qualities do have meaning. I would suggest ordering your
query (perhaps on a "row update time" if by "the last row" you mean "the
more recently entered row") using the "DESC" qualifier in the ORDER BY
clause, then use a cursor to pick up the first row returned.
Good luck.
- Tom
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [INTERFACES] the last row in a table
1999-03-09 12:08 the last row in a table hoelc <hoelc@pd.jaring.my>
@ 1999-03-09 19:30 ` Michael Meskes <meskes@postgresql.org>
3 siblings, 0 replies; 8+ messages in thread
From: Michael Meskes @ 1999-03-09 19:30 UTC (permalink / raw)
To: hoelc <hoelc@pd.jaring.my>; +Cc: pgsql-interfaces
On Tue, Mar 09, 1999 at 08:08:43PM +0800, hoelc wrote:
> I am developing a database with PostgreSQL in Linux, and using ecpg to write the
> C program to communicate with the database.
Nice to hear that. :-)
> One of my application need to get the data from the last row in a table.
Now that statement is sort of a problem. In a relational model there is no
order of tuples in a relation. You can simulate this via a unique key of
course or maybe use the OID. Or do you mean the last tuple of a query?
> Is there any function or command that can tract which is the last row of data in
> a table?
Once you opened a cursor you can move it to the end of the query via the
move command. I never used this feature but I take it this is how it is
supposed to be. Afterwards you can fetch one record backward.
Michael
--
Michael Meskes | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz | Go Rhein Fire!
Tel.: (+49) 2431/72651 | Use Debian GNU/Linux!
Email: Michael.Meskes@gmx.net | Use PostgreSQL!
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [GENERAL] Re: [INTERFACES] the last row in a table
1999-03-09 12:08 the last row in a table hoelc <hoelc@pd.jaring.my>
@ 1999-03-10 02:32 ` Marcin Grondecki <ojciec@mtl.pl>
1999-03-09 19:24 ` Re: [GENERAL] Re: [INTERFACES] the last row in a table Dustin Sallings <dustin@spy.net>
1999-03-10 11:38 ` Re: [GENERAL] Re: [INTERFACES] the last row in a table Stuart Rison <stuart@ludwig.ucl.ac.uk>
3 siblings, 2 replies; 8+ messages in thread
From: Marcin Grondecki @ 1999-03-10 02:32 UTC (permalink / raw)
To: pgsql-general@hub.org
At 15:20 99-03-09 +0000, you wrote:
>> I am developing a database with PostgreSQL in Linux, and using ecpg to
>> write the C program to communicate with the database.
>> One of my application need to get the data from the last row in a
>> table. Is there any function or command that can tract which is the
>> last row of data in a table?
>
>SQL is a set-oriented language. One should probably not assign any
>significance to a storage order of rows.
>
>It *is* possible to order the results of a query, and then your
>first/last qualities do have meaning. I would suggest ordering your
>query (perhaps on a "row update time" if by "the last row" you mean "the
>more recently entered row") using the "DESC" qualifier in the ORDER BY
>clause, then use a cursor to pick up the first row returned.
>
There is better answer, i think. Simply read smth about cursors - declaring,
using, droping. I think this is what u need.
In case of troubles with understanding, i'd serve with some examples in Perl.
Marcin Grondecki
ojciec@mtl.pl
+48(604)468725
***** I'm not a complete idiot, some parts are missing...
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [GENERAL] Re: [INTERFACES] the last row in a table
1999-03-09 12:08 the last row in a table hoelc <hoelc@pd.jaring.my>
1999-03-10 02:32 ` Re: [GENERAL] Re: [INTERFACES] the last row in a table Marcin Grondecki <ojciec@mtl.pl>
@ 1999-03-09 19:24 ` Dustin Sallings <dustin@spy.net>
1 sibling, 0 replies; 8+ messages in thread
From: Dustin Sallings @ 1999-03-09 19:24 UTC (permalink / raw)
To: Marcin Grondecki <ojciec@mtl.pl>; +Cc: pgsql-general@hub.org
On Tue, 9 Mar 1999, Marcin Grondecki wrote:
# There is better answer, i think. Simply read smth about cursors -
# declaring, using, droping. I think this is what u need. In case of
# troubles with understanding, i'd serve with some examples in Perl.
If it's the exact last input row you want, a trigger or rule would
be still yet better. :)
--
SA, beyond.com My girlfriend asked me which one I like better.
pub 1024/3CAE01D5 1994/11/03 Dustin Sallings <dustin@spy.net>
| Key fingerprint = 87 02 57 08 02 D0 DA D6 C8 0F 3E 65 51 98 D8 BE
L_______________________ I hope the answer won't upset her. ____________
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [GENERAL] Re: [INTERFACES] the last row in a table
1999-03-09 12:08 the last row in a table hoelc <hoelc@pd.jaring.my>
1999-03-10 02:32 ` Re: [GENERAL] Re: [INTERFACES] the last row in a table Marcin Grondecki <ojciec@mtl.pl>
@ 1999-03-10 11:38 ` Stuart Rison <stuart@ludwig.ucl.ac.uk>
1 sibling, 0 replies; 8+ messages in thread
From: Stuart Rison @ 1999-03-10 11:38 UTC (permalink / raw)
To: pgsql-general@postgresql.org
>On Tue, 9 Mar 1999, Marcin Grondecki wrote:
>
># There is better answer, i think. Simply read smth about cursors -
># declaring, using, droping. I think this is what u need. In case of
># troubles with understanding, i'd serve with some examples in Perl.
>
> If it's the exact last input row you want, a trigger or rule would
>be still yet better. :)
Or another possibility (again, if it's the last inputed row you want) is
SELECT * FROM <table> WHERE oid=( SELECT max(oid::float) FROM <table> );
I'm assuming here that the largest the oid the latest it was put in...
that's right isn't it (he said, all of a sudden hesitant).
Also, I could only get this to work by typecasting oid as float. Anybody
know why?
Regards,
Stuart.
+-------------------------+--------------------------------------+
| Stuart Rison | Ludwig Institute for Cancer Research |
+-------------------------+ 91 Riding House Street |
| Tel. (0171) 878 4041 | London, W1P 8BT, UNITED KINGDOM. |
| Fax. (0171) 878 4040 | stuart@ludwig.ucl.ac.uk |
+-------------------------+--------------------------------------+
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [GENERAL] the last row in a table
1999-03-09 12:08 the last row in a table hoelc <hoelc@pd.jaring.my>
@ 1999-03-10 08:42 ` Oleg Broytmann <phd@sun.med.ru>
3 siblings, 0 replies; 8+ messages in thread
From: Oleg Broytmann @ 1999-03-10 08:42 UTC (permalink / raw)
To: hoelc <hoelc@pd.jaring.my>; +Cc: pgsql-general@hub.org
Hi!
On Tue, 9 Mar 1999, hoelc wrote:
> I am developing a database with PostgreSQL in Linux, and using ecpg to write the
> C program to communicate with the database.
> One of my application need to get the data from the last row in a table.
> Is there any function or command that can tract which is the last row of data in
> a table?
Reorder your query to get the data in the FIRST row and use cursor to fetch
just the row.
> Thank you.
> Regards,
> lch
Oleg.
----
Oleg Broytmann National Research Surgery Centre http://sun.med.ru/~phd/
Programmers don't die, they just GOSUB without RETURN.
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [GENERAL] the last row in a table
@ 1999-03-09 14:23 K.T. <kanet@calmarconsulting.com>
0 siblings, 0 replies; 8+ messages in thread
From: K.T. @ 1999-03-09 14:23 UTC (permalink / raw)
To: hoelc@pd.jaring.my; pgsql-interfaces; +Cc: pgsql-admin@postgreSQL.org; pgsql-general@hub.org
How about...
select field1 where primary_key = select max(primary_key) from table;
or something like that :) I always mess up the parenthesis...cant remember
whether or not they are needed here around the second select.
-----Original Message-----
From: hoelc <hoelc@pd.jaring.my>
To: pgsql-interfaces@postgreSQL.org <pgsql-interfaces@postgreSQL.org>
Cc: pgsql-admin@postgreSQL.org <pgsql-admin@postgreSQL.org>;
pgsql-general@hub.org <pgsql-general@hub.org>
Date: Tuesday, March 09, 1999 7:03 AM
Subject: [GENERAL] the last row in a table
>Hello,
>I am developing a database with PostgreSQL in Linux, and using ecpg to
write the
>C program to communicate with the database.
>One of my application need to get the data from the last row in a table.
>Is there any function or command that can tract which is the last row of
data in
>a table?
>Thank you.
>Regards,
>lch
>
>
>
>
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~1999-03-10 11:38 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-03-09 12:08 the last row in a table hoelc <hoelc@pd.jaring.my>
1999-03-09 15:20 ` Thomas G. Lockhart <lockhart@alumni.caltech.edu>
1999-03-09 19:30 ` Michael Meskes <meskes@postgresql.org>
1999-03-10 02:32 ` Marcin Grondecki <ojciec@mtl.pl>
1999-03-09 19:24 ` Dustin Sallings <dustin@spy.net>
1999-03-10 11:38 ` Stuart Rison <stuart@ludwig.ucl.ac.uk>
1999-03-10 08:42 ` Oleg Broytmann <phd@sun.med.ru>
1999-03-09 14:23 Re: [GENERAL] the last row in a table K.T. <kanet@calmarconsulting.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox