From: | "Humble Geek" <humblegeek(at)rogers(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: PLSQL Question regarding multiple inserts |
Date: | 2004-02-25 18:59:45 |
Message-ID: | Bg6%b.3564$Yf.1085@twister01.bloor.is.net.cable.rogers.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thanks Greg.
That does help me some, however, I am stuck with this database (I have
inherited) - it has over a hundred tables, and while I may look into
converting it at some point, it is just unfeasible at this junction. So
where can I look to find the hard way? :)
HG
"Greg Patnude" <gpatnude(at)hotmail(dot)com> wrote in message
news:c1ir5r$2mhf$1(at)news(dot)hub(dot)org(dot)(dot)(dot)
> That's the hard way....
>
> You'd be better off redefining your table structures so that postgreSQL
> handles the primary keys automatically...
>
> CREATE TABLE test (
>
> id integer primary key not null default nextval('test_seq'),
> log varchar(32) NOT NULL,
> message text
>
> ) WITH OIDS;
>
> Using this type of table def will automatically create the sequence for
> you -- and always ge thte next value when you do an insert -- ensuring
that
> you dont have duplicate...
>
> so you would:
>
> INSERT INTO test ('log', 'message');
>
> then
>
> SELECT * FROM test;
>
> would give you
>
> id, log and message.
>
>
>
> --
> Greg Patnude / The Digital Demention
> 2916 East Upper Hayden Lake Road
> Hayden Lake, ID 83835
> (208) 762-0762
>
> "Humble Geek" <humblegeek(at)rogers(dot)com> wrote in message
> news:ZfV_b(dot)60$Yf(dot)1(at)twister01(dot)bloor(dot)is(dot)net(dot)cable(dot)rogers(dot)com(dot)(dot)(dot)
> > Hi all. Quick and perhaps silly question, but...
> >
> > I am using Pg 7.3. I am writing a function using pgplsql. This function
> will
> > perform multiple inserts. Let's say two of the inserts are as follows:
> >
> > -- id is primary key
> > insert into users (id, username) values (nextval('someSeq'),'somename');
> >
> > -- id is also a PK
> > insert into log (id, uid, message) values
> (nextval('someOtherSeq'),XXX,'New
> > Account');
> >
> > Assume XXX is the id from the first insert. How do I get that number?
Not
> > currval('someSeq') - 'cause someone else may have performed an insert -
> but
> > the id for that specific insert.
> >
> > Thanks,
> >
> > HG
> >
> > PS: Sorry for the cross-post...
> >
> >
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Martijn van Oosterhout | 2004-02-25 19:21:08 | Re: REINDEX issues |
Previous Message | Greg Patnude | 2004-02-25 18:51:25 | Re: PLSQL Question regarding multiple inserts |