Postgres 改变视图添加列
Postgres alter view add column
我想更改视图并在其中添加新列。我有:
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: syntax error at or near "AS"
第一次接触view,求助:)
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
代替
在您的情况下,它将类似于:
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;
我想更改视图并在其中添加新列。我有:
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: syntax error at or near "AS"
第一次接触view,求助:)
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
代替
在您的情况下,它将类似于:
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;