Re: parametered views

From: Alban Hertroys <alban(at)magproductions(dot)nl>
To: Rodrigo De León <rdeleonp(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: parametered views
Date: 2007-06-11 09:43:02
Message-ID: 466D1926.6030401@magproductions.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Rodrigo De León wrote:
> On Jun 8, 7:59 pm, "lhaj(dot)mer(dot)(dot)(dot)(at)gmail(dot)com" <lhaj(dot)mer(dot)(dot)(dot)(at)gmail(dot)com>
> wrote:
>> i have 4 tables :
>>
>> date_table (date_id,.....)
>> A_table(A_table_id, something1,something2.........)
>> A1_table(A1_table_id references A_Table(A_Table_id),A11,A12........)
>> A2_table(A2_table_id references A_Table(A_table_id),A21,A22,.......)
>>
>> so i want to create a view with date_id,A_table_id,something1,
>> if something2=x then my view containts
>> (A1_table.A11 and A1_table.A12)
>> else it's containts (A2_table.A21 and A2_table.A22))
>>
>> so my view depends of something2 value.
>>
>> I hope i'm specific
>>
>> Thx
>> Lhaj
>
> create view foobar as
> select date_id,A_table_id,something1
> ,case when something2=x then A1_table.A11 else A2_table.A21 end as foo
> ,case when something2=x then A1_table.A12 else A2_table.A22 end as bar
> from (... etc., etc. ...)

Not sure what you're trying to say here... You didn't formulate a question.

Maybe you mean this?:

CREATE VIEW foobar AS
SELECT date_id, A_table_id, A1_table.A11, A1_table.A12
WHERE something2 = x
UNION
SELECT date_id, A_table_id, A2_table.A21, A2_table.A22
WHERE something2 <> x

In case the records in the result sets matching something2 = x and the
ones not matching are distinct or if you don't care about duplicates,
use UNION ALL instead of UNION.

--
Alban Hertroys
alban(at)magproductions(dot)nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
7500 AK Enschede

// Integrate Your World //

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rikard Pavelic 2007-06-11 10:19:40 track ddl changes on single database
Previous Message Alban Hertroys 2007-06-11 09:01:36 Re: Postmaster processes taking all the CPU