pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jamie Lawrence <postgres@jal.org>
To: pgsql-sql@postgresql.org
Subject: Rule definition problem
Date: Thu, 24 Apr 2003 14:11:09 -0500
Message-ID: <20030424191109.GY15321@jal.clueinc.net> (raw)

Hi all -

I'm trying to define rules for inserts and updates on a view. My problem
is that I'm unsure on how to get the value of a field on one table and
use it in an insert into another.

The tables in question have a one-one relationship (A little warped, I
know; the 'inventory' table has data common to all items, and the
'music' table has data specific to, well, inventory items of type
'music'.)

The underlying tables and the view look something like this:

create table inventory (
        id serial unique not null,
        manufacturer_num text unique,
        category_id int not null,
        [...] );

create table music (
        id serial unique not null,
        inventory_id int not null,
        year int,
        label text,
        [...]
        CONSTRAINT category_exists foreign key (inventory_id)
        references inventory (id) on delete cascade );


create view music_view as
        select inventory.id,
        inventory.manufacturer_num,
        inventory.category_id,
        [...],
        music.year,
        music.label,
        [...]
        from inventory, music
        where inventory.id = music.inventory_id;


For an Insert rule, I need to get the value of inventory.id we just
inserted and stash it in music.inventory_id.

Is this possible in a rule, or do I need to do with in a trigger? Am I
on crack?

TIA.

-j




-- 
Jamie Lawrence                                        jal@jal.org
Non-linear physics is like non-elephant biology.




view thread (3+ messages)  latest in thread

Message-ID: <20030424191109.GY15321@jal.clueinc.net>
Permalink:  ../20030424191109.GY15321@jal.clueinc.net/
Also on:    postgresql.org/message-id/20030424191109.GY15321@jal.clueinc.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: postgres@jal.org
  Subject: Re: Rule definition problem
  In-Reply-To: <20030424191109.GY15321@jal.clueinc.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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