Is your feature request related to a problem?
The typechecker silently skips the query inside CREATE TABLE ... AS SELECT,
CREATE MATERIALIZED VIEW ... AS SELECT and CREATE VIEW ... AS SELECT. Neither an
unknown column nor an unknown table is reported.
This matters for ETL and analytics codebases, where CREATE TABLE AS is the dominant
shape. In ours it is roughly 640 files out of 1880: the tool reports nothing on a third
of the codebase, and the absence of a diagnostic reads as a pass.
Describe the solution you'd like
Typecheck the inner query for these forms.
For CREATE TABLE AS and CREATE MATERIALIZED VIEW AS this looks cheap, because
Postgres accepts EXPLAIN on both and surfaces the error itself:
postgres=# EXPLAIN CREATE TABLE t2 AS SELECT t.nope FROM t;
ERROR: column t.nope does not exist
postgres=# EXPLAIN CREATE MATERIALIZED VIEW mv1 AS SELECT t.nope FROM t;
ERROR: column t.nope does not exist
CREATE VIEW is the odd one out, since EXPLAIN CREATE VIEW is a syntax error in
Postgres. That one would need the inner SELECT to be extracted and checked on its own.
Current behavior
Against a database with CREATE TABLE t (a INT);:
| Statement |
Diagnostic |
SELECT t.nope FROM t; |
42703 reported |
INSERT INTO t (a) SELECT t.nope FROM t; |
42703 reported |
CREATE TABLE t2 AS SELECT t.nope FROM t; |
none |
CREATE TABLE t3 AS SELECT t.a FROM nonexistent_table AS t; |
none |
CREATE VIEW v1 AS SELECT t.nope FROM t; |
none |
CREATE MATERIALIZED VIEW mv1 AS SELECT t.nope FROM t; |
none |
System information
- postgres-language-server 0.25.7, Postgres 15
- macOS (aarch64), release binary
postgres-language-server_aarch64-apple-darwin
Is your feature request related to a problem?
The typechecker silently skips the query inside
CREATE TABLE ... AS SELECT,CREATE MATERIALIZED VIEW ... AS SELECTandCREATE VIEW ... AS SELECT. Neither anunknown column nor an unknown table is reported.
This matters for ETL and analytics codebases, where
CREATE TABLE ASis the dominantshape. In ours it is roughly 640 files out of 1880: the tool reports nothing on a third
of the codebase, and the absence of a diagnostic reads as a pass.
Describe the solution you'd like
Typecheck the inner query for these forms.
For
CREATE TABLE ASandCREATE MATERIALIZED VIEW ASthis looks cheap, becausePostgres accepts
EXPLAINon both and surfaces the error itself:CREATE VIEWis the odd one out, sinceEXPLAIN CREATE VIEWis a syntax error inPostgres. That one would need the inner
SELECTto be extracted and checked on its own.Current behavior
Against a database with
CREATE TABLE t (a INT);:SELECT t.nope FROM t;42703reportedINSERT INTO t (a) SELECT t.nope FROM t;42703reportedCREATE TABLE t2 AS SELECT t.nope FROM t;CREATE TABLE t3 AS SELECT t.a FROM nonexistent_table AS t;CREATE VIEW v1 AS SELECT t.nope FROM t;CREATE MATERIALIZED VIEW mv1 AS SELECT t.nope FROM t;System information
postgres-language-server_aarch64-apple-darwin