Re: Create a view with variable amount of columns depending on the rows of a table

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Stefan Gündhör <stefan(at)guendhoer(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Create a view with variable amount of columns depending on the rows of a table
Date: 2011-03-14 20:04:44
Message-ID: AANLkTi=QAW92JBpi8=mgdaNKocp6y_df4Xmx3XJhWAMW@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2011/3/14 Stefan Gündhör <stefan(at)guendhoer(dot)com>:
> Hi,
> If I have following tables for example:
> # Main Table:
> id(id/pk) | geometry
> ---------------------------
> 1           | ...
> # Additional Attribute Table:
> name(id/pk) | value
> ---------------------------
> date_added | 20.12.1988
> name          | Vienna
> # m:n table:
> mainTableID | attrTableID
> -----------------------------------
> 1                 | date_added
> 1                 | name
> And i would like to automatically generate a View like
> the following:
> id(id/pk) | geometry | date_added | name
> -----------------------------------------------------------
> 1           | ...           | 20.12.1988  | Vienna
> This example is a simplified (and not really functional) version of what I
> would like to do -
> but it should make clear what I have in view: Dynamically generating a
> View's columns depending on the rows of a table.
> Does anybody know, if this is possible?
> Thank you for your replies in advance,
> best regards,
> Stefan Gündhör

The columns in a view are strictly defined when you 'create view'.
However, nothing is stopping you from implementing triggers that
EXECUTE 'create view' from a plpgsql function if that's what you'd
like to do, as long as you are willing to deal with the headaches
surrounding that approach. ISTM though that there is probably a
simpler solution to your problem though than manipulating view
definitions.

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2011-03-14 20:13:57 Re: Move From Oracle DB to PostgreSQL DB
Previous Message John R Pierce 2011-03-14 19:37:53 Re: Move From Oracle DB to PostgreSQL DB