Unix Technical Forum

parametered views

This is a discussion on parametered views within the Pgsql General forums, part of the PostgreSQL category; --> Hello, my problem is : in depend of the value of a field in a table A, I want ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 05:48 PM
lhaj.merigh@gmail.com
 
Posts: n/a
Default parametered views

Hello,

my problem is : in depend of the value of a field in a table A, I
want to select other fields coming from a table B, or a table C.

I want to know if it's possible to create a parametred view in
postgresql to resolve this problem


Thx,
Lhaj

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 05:48 PM
=?iso-8859-1?q?Rodrigo_De_Le=F3n?=
 
Posts: n/a
Default Re: parametered views

lhaj.merigh@gmail.com ha escrito:
> Hello,
>
> my problem is : in depend of the value of a field in a table A, I
> want to select other fields coming from a table B, or a table C.
>
> I want to know if it's possible to create a parametred view in
> postgresql to resolve this problem
>
>
> Thx,
> Lhaj


You really should be more specific...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 05:48 PM
lhaj.merigh@gmail.com
 
Posts: n/a
Default Re: parametered views

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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-09-2008, 05:48 PM
=?iso-8859-1?q?Rodrigo_De_Le=F3n?=
 
Posts: n/a
Default Re: parametered views

On Jun 8, 7:59 pm, "lhaj.mer...@gmail.com" <lhaj.mer...@gmail.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. ...)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-09-2008, 05:48 PM
lhaj.merigh@gmail.com
 
Posts: n/a
Default Re: parametered views

On Jun 9, 8:12 am, Rodrigo De León <rdele...@gmail.com> wrote:
> On Jun 8, 7:59 pm, "lhaj.mer...@gmail.com" <lhaj.mer...@gmail.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. ...)


OK, thank you (the idea is here i will try to do that)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-09-2008, 05:49 PM
Alban Hertroys
 
Posts: n/a
Default Re: parametered views

Rodrigo De León wrote:
> On Jun 8, 7:59 pm, "lhaj.mer...@gmail.com" <lhaj.mer...@gmail.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@magproductions.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 //


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:19 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com