Re: SQL INSERT/TRIGGER Help

Поиск
Список
Период
Сортировка
От Poovendran Moodley
Тема Re: SQL INSERT/TRIGGER Help
Дата
Msg-id b18bbf6f0712100113h5937e2c3pcc0ef236e3733635@mail.gmail.com
обсуждение исходный текст
Ответ на Re: SQL INSERT/TRIGGER Help  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Список pgsql-sql
Aww man thank you so much! It worked like a charm! Have a smashing day :D<br /><br /><div class="gmail_quote">On Dec
10,2007 9:43 AM, A. Kretschmer <<a href="mailto:andreas.kretschmer@schollglas.com">andreas.kretschmer@schollglas.com
</a>>wrote:<br /><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt
0pt0.8ex; padding-left: 1ex;">am  Mon, dem 10.12.2007, um  9:27:58 +0200 mailte Poovendran Moodley folgendes: <br
/><divclass="Ih2E3d">> I'm not really sure how to the currval() method. I've read up on it and I<br />> noticed
itworks with nextval() and setval(). The parameter for currval() is a<br />> regex - is there a regex to represent
themost recently automatically generated <br />> number ( i.e. a serial field)? If there isn't, I was thinking that
atrigger<br />> could be used so that when an INSERT is executed against the Observation_Value<br /><br /><br
/></div>Okay,i explain this a little bit more: <br /><br />first, i create two tables, master and slave. master
containsa<br />serial-field, this field is referenced by the slave table:<br /><br />test=# create table master (id
serialprimary key, name text);<br />NOTICE:  CREATE TABLE will create implicit sequence "master_id_seq" for serial
column" <a href="http://master.id" target="_blank">master.id</a>"<br />NOTICE:  CREATE TABLE / PRIMARY KEY will create
implicitindex "master_pkey" for table "master"<br />CREATE TABLE<br />test=*# create table slave(master_id int
referencesmaster, val text); <br />CREATE TABLE<br /><br /><br />Now i have 2 tables and a sequence named
'master_id_seq',and now the<br />insert's:<br /><br /><br />test=*# insert into master (name) values ('test');<br
/>INSERT0 1<br />test=*# insert into slave (master_id, val) values (currval('master_id_seq'), 'value'); <br />INSERT 0
1<br/><br /><br /><br />The parameter for currval() is the name of the sequence. Note: you have to<br />insert in the
mastertable first, this calls the nextval() for the<br />sequence. After, within this database session, you can use
currval()to <br />obtain the actual value for this sequence. And yes, this way is safe<br />also for concurrency.<br
/><divclass="Ih2E3d"><br /><br />Andreas<br />--<br />Andreas Kretschmer<br />Kontakt:  Heynitz: 035242/47150,   D1:
0160/7141639(mehr: -> Header) <br />GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   <a href="http://wwwkeys.de.pgp.net"
target="_blank">http://wwwkeys.de.pgp.net</a><br/><br />---------------------------(end of
broadcast)---------------------------<br/></div>TIP 6: explain analyze is your friend <br /></blockquote></div><br /> 

В списке pgsql-sql по дате отправления:

Предыдущее
От: "A. Kretschmer"
Дата:
Сообщение: Re: SQL INSERT/TRIGGER Help
Следующее
От: "Stefan Scheidegger"
Дата:
Сообщение: Re: INSERT INTO relational tables