postgresql Postgres 更改视图添加列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29047062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:49:36  来源:igfitidea点击:

Postgres alter view add column

postgresqlview

提问by arual

I want to alter a view and add a new column in it. I have:

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

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

The problem is that it shows:

问题是它显示:

[Err] ERROR: syntax error at or near "AS"

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

Is the first time I have to do with views, I need some help :)

我是第一次处理视图,我需要一些帮助:)

回答by Houari

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

Use CREATE OR REPLACEINSTEAD

使用CREATE OR REPLACE代替

In your case, it will be something like:

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

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

来源