gpt4 book ai didi

postgresql - Postgres 改变 View 添加列

转载 作者:行者123 更新时间:2023-11-29 11:20:23 24 4
gpt4 key购买 nike

我想改变一个 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: 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 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

关于postgresql - Postgres 改变 View 添加列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29047062/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com