Parse error when aliasing a sub-select
Closed this issue · 2 comments
gregsexton commented
Trying to create a view:
CREATE VIRTUAL VIEW control_plane_create_db_outstanding_requests AS
SELECT reqs.id, reqs.skdb_author, reqs.skdb_access, reqs.db_name, res.success
FROM control_plane_create_db_requests reqs
LEFT OUTER JOIN (SELECT * FROM control_plane_create_db_results WHERE success IS NULL OR success < 1) AS res
ON reqs.id = res.id;
Getting the error:
CREATE VIRTUAL VIEW control_plane_create_db_outstanding_requests AS
SELECT reqs.id, reqs.skdb_author, reqs.skdb_access, reqs.db_name, res.success
FROM control_plane_create_db_requests reqs
LEFT OUTER JOIN (SELECT * FROM control_plane_create_db_results WHERE success IS NULL OR success < 1) AS res
^
|
----- ERROR
Error: line 20, character 106:
Unexpected token AS: expected SEMICOLON or EOF
gregsexton commented
CREATE VIRTUAL VIEW create_db_non_success_results AS SELECT * FROM control_plane_create_db_results WHERE success IS NULL OR success < 1;
CREATE VIRTUAL VIEW control_plane_create_db_outstanding_requests AS
SELECT reqs.id, reqs.skdb_author, reqs.skdb_access, reqs.db_name, res.success
FROM control_plane_create_db_requests reqs
LEFT OUTER JOIN create_db_non_success_results AS res
ON reqs.id = res.id;
This works.
gregsexton commented
CREATE VIRTUAL VIEW create_db_non_success_results AS SELECT * FROM control_plane_create_db_results WHERE success IS NULL OR success < 1;
CREATE VIRTUAL VIEW control_plane_create_db_outstanding_requests AS
SELECT reqs.id, reqs.skdb_author, reqs.skdb_access, reqs.db_name, res.success
FROM control_plane_create_db_requests reqs
LEFT OUTER JOIN create_db_non_success_results res
ON reqs.id = res.id;
So does this (without the AS, which I generally drop).