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

Re: Last ID Problem

From: <operationsengineer1(at)yahoo(dot)com>
To: "Vishal Kashyap (at) [SaiHertz]" <vishalonlist(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Last ID Problem
Date: 2005-01-31 19:36:11
Message-ID: 20050131193611.97235.qmail@web52409.mail.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-novice
Vishal,

will your suggestion protect my db if I have two
customers with the same name?  does it always return
the highest cust_id and is that *always* the last
cust_id entered?

tia...

--- "Vishal Kashyap @ [SaiHertz]"
<vishalonlist(at)gmail(dot)com> wrote:

> Hi,
> 
> > $id = "SELECT currval('cust_id')"; // used in an
> > attempt to get last id (colum 'cust id')entered
> into
> > db.
> > 
> > $result = $db->Execute($sql);  // works fine.
> > 
> > $id_result = $db->execute($id);  // $id_result has
> no
> > value.
> 
> This is because currval fetched data during a
> transaction process and
> not after the process  is complete.
> 
> the best way I suggest is  
> 
>  $id = "SELECT cust_id from customer  where
> customer_name ='$cust'
> order by cust_id desc limit1" ; // used in an
> 
> -- 
> With Best Regards,
> Vishal Kashyap.
> Lead Software Developer,
> http://saihertz.com,
> http://vishalkashyap.tk
> 
> ---------------------------(end of
> broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
>                http://archives.postgresql.org
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

In response to

Responses

pgsql-novice by date

Next:From: Michael FuhrDate: 2005-01-31 19:46:01
Subject: Re: How to learn Postgres?
Previous:From: Vishal Kashyap @ [SaiHertz]Date: 2005-01-31 19:25:55
Subject: Re: Last ID Problem

pgsql-hackers by date

Next:From: Tom LaneDate: 2005-01-31 19:36:33
Subject: Re: [BUGS] Bug in create operator and/or initdb
Previous:From: Greg StarkDate: 2005-01-31 19:35:58
Subject: Re: [BUGS] Bug in create operator and/or initdb

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