Postgres改变视图添加列

时间:2015-03-14 08:37:20

标签: postgresql view

我想更改视图并在其中添加新列。我有:

ALTER VIEW folders_contents
AS
SELECT files.id,
    files.name,
    files.filesize,
    files.updated,
    files.deleted,
   FROM files
UNION ALL
 SELECT folders.id,
    folders.name,
    0 AS filesize,
    folders.updated,
    folders.deleted,
    FROM folders
  ORDER BY 8, 2
GO

问题在于它显示:

  

[Err] ERROR:“AS”或附近的语法错误

我是第一次使用视图,我需要一些帮助:)

1 个答案:

答案 0 :(得分:17)

ALTER VIEW changes various auxiliary properties of a view. 
(If you want to modify the view's defining query, use CREATE OR REPLACE VIEW.)

使用CREATE OR REPLACE INSTEAD

在您的情况下,它将类似于:

CREATE OR REPLACE VIEW folders_contents
AS
SELECT files.id,
    files.name,
    files.filesize,
    files.updated,
    files.deleted,
   FROM files
UNION ALL
 SELECT folders.id,
    folders.name,
    0 AS filesize,
    folders.updated,
    folders.deleted,
    FROM folders
  ORDER BY 8, 2;

SOURCE