pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedINSERT FOLLOW WITH OTHER INSERT
2+ messages / 2 participants
[nested] [flat]
* INSERT FOLLOW WITH OTHER INSERT
@ 2001-08-10 03:43 Johny Jugianto <johny.q@rocketmail.com>
2001-08-10 11:17 ` Re: INSERT FOLLOW WITH OTHER INSERT Bhuvan A <bhuvansql@yahoo.com>
0 siblings, 1 reply; 2+ messages in thread
From: Johny Jugianto @ 2001-08-10 03:43 UTC (permalink / raw)
To: pgsql-sql
hi all
i have a table like this
CREATE SEQUENCE seq_student_id INCREMENT 1 START 1;
CREATE TABLE students (
student_id INT4 NOT NULL DEFAULT
NEXTVAL('seq_student_id'),
student_name text,
student_address text,
primary key(student_id)
)
CREATE TABLE student_club (
student_id INT4 NOT NULL;
club_id INT4,
CONSTRAINT student_id_update FOREIGN KEY(student_id)
REFERENCES students(student_id) ON UPDATE CASCADE
)
my question is how i can make auto insert student_id
on table student_club when i insert into table
students
example:
INSERT INTO students(student_name) VALUES('Willy');
table STUDENT
student_id | name | address
---------------------------------
1 | Willy |
and on TABLE student_club
student_id | club_id
--------------------
1 |
i have trying with create rule and with
check_foreign_key, but i haven't found solution.
anyone can help me?
Thanks in advance
__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: INSERT FOLLOW WITH OTHER INSERT
2001-08-10 03:43 INSERT FOLLOW WITH OTHER INSERT Johny Jugianto <johny.q@rocketmail.com>
@ 2001-08-10 11:17 ` Bhuvan A <bhuvansql@yahoo.com>
0 siblings, 0 replies; 2+ messages in thread
From: Bhuvan A @ 2001-08-10 11:17 UTC (permalink / raw)
To: Johny Jugianto <johny.q@rocketmail.com>; +Cc: pgsql-sql
Are you ready to solve your problem using a trigger and 'plpgsql'
function ?? ..
then proceed ..
trigger :)
+++++++++++++++++++++++++++++++++++++++++++
CREATE TRIGGER trigger_student_club
before INSERT OR UPDATE
ON students
FOR EACH ROW
EXECUTE PROCEDURE ins_student_club_func();
+++++++++++++++++++++++++++++++++++++++++++
function :)
+++++++++++++++++++++++++++++++++++++++++++
CREATE FUNCTION ins_student_club_func()
RETURNS OPAQUE
AS
'BEGIN
INSERT INTO student_club(student_id) VALUES
(new.student_id);
return new;
END;'
LANGUAGE 'plpgsql';
+++++++++++++++++++++++++++++++++++++++++++
Hope it works. :)
Regards,
Bhuvaneswar.
On Aug 9, Johny Jugianto wrote:
> hi all
>
> i have a table like this
>
> CREATE SEQUENCE seq_student_id INCREMENT 1 START 1;
> CREATE TABLE students (
> student_id INT4 NOT NULL DEFAULT
> NEXTVAL('seq_student_id'),
> student_name text,
> student_address text,
> primary key(student_id)
> )
> CREATE TABLE student_club (
> student_id INT4 NOT NULL;
> club_id INT4,
> CONSTRAINT student_id_update FOREIGN KEY(student_id)
> REFERENCES students(student_id) ON UPDATE CASCADE
> )
>
> my question is how i can make auto insert student_id
> on table student_club when i insert into table
> students
>
> example:
> INSERT INTO students(student_name) VALUES('Willy');
>
> table STUDENT
> student_id | name | address
> ---------------------------------
> 1 | Willy |
>
> and on TABLE student_club
> student_id | club_id
> --------------------
> 1 |
>
>
> i have trying with create rule and with
> check_foreign_key, but i haven't found solution.
> anyone can help me?
>
> Thanks in advance
>
>
> __________________________________________________
> Do You Yahoo!?
> Make international calls for as low as $.04/minute with Yahoo! Messenger
> http://phonecard.yahoo.com/
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2001-08-10 11:17 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-08-10 03:43 INSERT FOLLOW WITH OTHER INSERT Johny Jugianto <johny.q@rocketmail.com>
2001-08-10 11:17 ` Bhuvan A <bhuvansql@yahoo.com>
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