pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: [INTERFACES] How can I work thru this key problem?
3+ messages / 3 participants
[nested] [flat]

* Re: [INTERFACES] How can I work thru this key problem?
@ 1999-07-26 17:39  Jeffrey Lyon <lyonj@em-systems.com>
  parent: marc rassbach <marc@tandem.milestonerdl.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Jeffrey Lyon @ 1999-07-26 17:39 UTC (permalink / raw)
  To: marc rassbach <marc@tandem.milestonerdl.com>; +Cc: pgsql-interfaces@postgreSQL.org


There's probably a better way, but I do a:

SELECT NEXTVAL('thenextkey') AS n_thenextkey;
INSERT INTO exampletable (keyiwant, otherinfo) VALUES (n_thenextkey,
'somestring');

...and then use n_thenextkey to refer to the newly added tuple.

Jeffrey


On Mon, 26 Jul 1999, marc rassbach wrote:

> I am using
> 6.5 postgresql
> DBD pg 0.91
> DBI 1.08
> 
> I have a table that looks like:
> 
> create table exampletable (
> keyiwant      int4 default nextval('thenextkey') not null,
> otherinfo     varchar(20)
> );
> 
>  
> When I place, oh say the string "Whatsmyid" into exampletable, I'd like to
> be able to know the value of keyiwant is, without going back and doing a
> select keyiwant from exampletable where otherinfo = "Whatsmyid"
> 
> Ideas on how I can get to where I want to go?
> 
> 
> 




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* How can I work thru this key problem?
@ 1999-07-26 17:50  marc rassbach <marc@tandem.milestonerdl.com>
  0 siblings, 2 replies; 3+ messages in thread

From: marc rassbach @ 1999-07-26 17:50 UTC (permalink / raw)
  To: pgsql-interfaces@postgreSQL.org

I am using
6.5 postgresql
DBD pg 0.91
DBI 1.08

I have a table that looks like:

create table exampletable (
keyiwant      int4 default nextval('thenextkey') not null,
otherinfo     varchar(20)
);

 
When I place, oh say the string "Whatsmyid" into exampletable, I'd like to
be able to know the value of keyiwant is, without going back and doing a
select keyiwant from exampletable where otherinfo = "Whatsmyid"

Ideas on how I can get to where I want to go?





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [INTERFACES] How can I work thru this key problem?
@ 1999-07-27 14:36  Herouth Maoz <herouth@oumail.openu.ac.il>
  parent: marc rassbach <marc@tandem.milestonerdl.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Herouth Maoz @ 1999-07-27 14:36 UTC (permalink / raw)
  To: marc rassbach <marc@tandem.milestonerdl.com>; pgsql-sql

At 20:50 +0300 on 26/07/1999, marc rassbach wrote:


>
> When I place, oh say the string "Whatsmyid" into exampletable, I'd like to
> be able to know the value of keyiwant is, without going back and doing a
> select keyiwant from exampletable where otherinfo = "Whatsmyid"
>
> Ideas on how I can get to where I want to go?

Yes, after the INSERT, do:

SELECT currval('thenextkey');

This gives you the latest value of the sequence which your current session
has produced. Yes, it is multiuser-safe - no other process will receive the
number you produced except you.

BTW, this shouldn't be in the interfaces list. It's an SQL question.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~1999-07-27 14:36 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-07-26 17:50 How can I work thru this key problem? marc rassbach <marc@tandem.milestonerdl.com>
1999-07-26 17:39 ` Jeffrey Lyon <lyonj@em-systems.com>
1999-07-27 14:36 ` Herouth Maoz <herouth@oumail.openu.ac.il>

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