SQL View别名在H2 SELECT语句中不起作用

问题描述 投票:0回答:1

我有一个表student和一个视图annual_performance。我正在创建如下的视图student_annual_performance

CREATE OR REPLACE VIEW student_annual_performance AS SELECT
s, ap
FROM student s INNER JOIN annual_performance ap ON s.id = ap.studentId;

在PostgreSQL中工作正常,但在H2内存数据库中出现以下错误

SQL状态:42S22错误代码:42122消息:找不到“ ap”列; SQL语句:

database select view alias h2
1个回答
0
投票

您使用了其他数据库中不存在的特定于PostgreSQL的神秘功能。在H2和大多数其他数据库中,不能使用表(视图)名称或其别名作为值表达式。

您可以在两个数据库中代替使用… AS SELECT (s.column1, s.column2, …) s, (ap.column1, ap.column2, …) ap FROM …,其中column1column2等是表student和视图annual_performance中的列的名称,以得到相同的结果。

您还可以使用… AS SELECT * FROM …来获取单独列中的所有值。

© www.soinside.com 2019 - 2024. All rights reserved.