pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robins Tharakan <tharakan@gmail.com>
To: Patric <lists@p-dw.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Saving result set of SELECT to table column
Date: Tue, 15 Jan 2008 09:00:27 +0530
Message-ID: <36af4bed0801141930r4bcaf94cqed26557899fc578b@mail.gmail.com> (raw)
In-Reply-To: <478BA7B8.2090907@p-dw.com>
References: <478BA7B8.2090907@p-dw.com>

Hi Patric,

This doesn't seem to be a question pertaining to the PERFORM queue.

If I understand you correctly, this should solve your problems, without the
need for any RULES / TRIGGERS.

CREATE TABLE y
(
  y1 int4 NOT NULL,
  y2 varchar,
  CONSTRAINT a PRIMARY KEY (y1)
)


CREATE TABLE z
(
  z1 int4 NOT NULL,
  z2 varchar,
  CONSTRAINT zz PRIMARY KEY (z1)
)



CREATE TABLE x
(
  x1 int4 NOT NULL,
  xy1 int4 NOT NULL,
  xz1 int4 NOT NULL,
  xy2 varchar,
  xz2 varchar,
  CONSTRAINT xa PRIMARY KEY (x1),
  CONSTRAINT xy1 FOREIGN KEY (xy1)
      REFERENCES y (y1) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT xz1 FOREIGN KEY (xz1)
      REFERENCES z (z1) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)


INSERT INTO x (x1, xy1, xz1, xy2, xz2)
SELECT 1, y1, z1, y2, z2
FROM y, z
WHERE y1 = 1
    AND z1 = 1;


*Robins*

On Jan 14, 2008 11:49 PM, Patric <lists@p-dw.com> wrote:

> Hi,
>   There will be some flames i suppose.
>   Well I've a normalized database..
>   For instance:
>
>   create table Y ( pk, data...  );
>   create table Z ( pk , data...    );
>
>   create table X (  char, references  Y, references  Z);
>
>   SELECT * from X;
>
>   Now I want to make a listing of the result set from X.
>   If there are references to Z or Y (not null refs), I want to display
> that data too.
>
>   Normally I would SELECT, to get that data, not in my case.
>   Nearly all queries will be SELECTs, no UPDATEs or INSERTs, so need to
> optimize that case.
>
>   The dirty little denormalization would look like this:
>
>   create table X ( char, ref. to Y, ref. to Z, StoreY Y , StoreZ Z);
>
>   On insert or update of Z or Y, I would update these two (StoreY,
> StoreZ) columns by RULE or TRIGGER..
>   I know this is not nice etc.. Codd would sue for this, but in my case
> performance over beauty is ok.
>     I'm looking for something like UPDATE X set StoreY=(SELECT * FROM Y
> WHERE pk=4) WHERE foreignID2Y = 4;
>
>   Is there a away to accomplish this straightforward  in a single
> statement without doing loops and stuff in a serverside procedure?
>
>  Thanks in advance,
>   Patric
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>

view thread (3+ messages)

Message-ID: <36af4bed0801141930r4bcaf94cqed26557899fc578b@mail.gmail.com>
Permalink:  ../36af4bed0801141930r4bcaf94cqed26557899fc578b@mail.gmail.com/
Also on:    postgresql.org/message-id/36af4bed0801141930r4bcaf94cqed26557899fc578b@mail.gmail.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: tharakan@gmail.com, lists@p-dw.com
  Subject: Re: Saving result set of SELECT to table column
  In-Reply-To: <36af4bed0801141930r4bcaf94cqed26557899fc578b@mail.gmail.com>
  References: <478BA7B8.2090907@p-dw.com> <36af4bed0801141930r4bcaf94cqed26557899fc578b@mail.gmail.com>

* 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