Skip site navigation (1) Skip section navigation (2)

Create a row-wise conditional view

From: Pedro Tarrafeta <ptarra(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Create a row-wise conditional view
Date: 2005-07-22 18:12:16
Message-ID: c3998f1505072211122b93d3b3@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Hi,

I'm trying to create a set of views like this. Let's say I have 2 tables 
with the same structure. One of them is the "master" table (left side) and 
the other one has a different "version" of the fields only for certain rows.

I want to create a view that would have the same structure as the tables, 
holding all the records from the master table but when there's a record 
matching on the secundary then use those. 

This doesn't work on Postgresql 8.0.3 but is very close to what I need:
CREATE VIEW work_view AS
SELECT CASE WHEN table2.id <http://table2.id> IS NULL THEN table1.*
ELSE table2.*
END

I can use COALESCE but this is field after field or compute multiple CASEs 
where the same condition is evaluated again and again, field after field and 
row after row...

Any ideas?
Thanks

Pedro

Thank you

Responses

pgsql-novice by date

Next:From: K. HoffrathDate: 2005-07-22 19:11:41
Subject: Possible problem when updating a record from two clients at the same time?
Previous:From: Oren MazorDate: 2005-07-22 17:53:22
Subject: Re: dead tuples

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group