[lug] (OT) postgresql
j davis
davis_compz at hotmail.com
Sun Nov 10 18:35:37 MST 2002
>> is there a postgresql select query i can enter to specify
>>the last row of a table...
>
> select max(inv_num) from customers;
>
>to get the specific invoice number, or
>
> select * from customers
> where inv_num = (select max(inv_num) from customers);
>
>to get the full row.
>
>>i.e. i want to make a new invoice number based
>>on the inv_num field of the last customer entry into a table.
>
>so you do NOT want to generate a new invoice number from the existing
>table. If you do, you must somehow guarantee that you will never establish
>more than a single connection to the database, and never more than one
>query at any time, otherwise your code may reuse the same invoice number
>because of concurrent access.
>
>What you really want to use is a "sequence" - it will guarantee uniqueness.
> IIRC, it's something like
>
> create sequence inv_num;
>
> select next_val(inv_num);
>
>You should also add 'unique' to the column constraints for your inv_num
>field. This will ensure that you never have two invoices with the same
>number.
>
>Bear
>
thanks everyone for the help...my sql knowelege has improved 10 fold..
now if i could just focus on spelling....
Xconfigurator,
jd
_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
More information about the LUG
mailing list