From: | Johan Nel <johan(dot)nel(at)xsinet(dot)co(dot)za> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: alter view, add/drop column |
Date: | 2012-09-05 15:15:24 |
Message-ID: | a87ec743-23eb-4209-bb95-3e5a9ea633d7@googlegroups.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Dave,
On Wednesday, 5 September 2012 16:16:32 UTC+2, "Gauthier, Dave" wrote:
> I googled around and found that adding/dropping columns from views is not available. (if not true, I'm all ears).
> Given that, what's the best way to do this? I was thinking along the lines of a stored procedure that reads the view's definition, modifies it, drops the view, recreates the view. The main concern here is that the view drop may fail if
> someone is using it. (is that a valid concern?). The procedure would take as args a verb (add/delete/rename), an object (column to operate on), new name (optional, not used for delete), maybe a table name to know where in the view def to add the new column.
You can do from pgAdmin by right-clicking on the view and select CREATE SCRIPT uncomment:
DROP VIEW <viewname>;
and edit the CREATE VIEW <viewname> to drop the column.
However if the view is used in other views you have to drop them all and recreate in sequence.
Alternatively you can delete the columns from the pg_catalog.pg_attribute table. Make sure however that you know you deleting only the one's you want to delete and not other tables columns... using the below:
delete from pg_attribute where attrelid = regclass 'yourviewname' and attname = 'columnnametodrop'
Best to first do couple of selects until you have the selection correct:
select attrelid::regclass as whatever, * from pg_attribute where attname = 'columnnametodrop'
Johan Nel.
From | Date | Subject | |
---|---|---|---|
Next Message | Aleksey Tsalolikhin | 2012-09-05 15:17:32 | Re: postgres process got stuck in "notify interrupt waiting" status |
Previous Message | Tom Lane | 2012-09-05 14:38:33 | Re: postgres process got stuck in "notify interrupt waiting" status |