diff --git a/src/operator/src/statement/ddl.rs b/src/operator/src/statement/ddl.rs index 6059cb3ebe78..222126952066 100644 --- a/src/operator/src/statement/ddl.rs +++ b/src/operator/src/statement/ddl.rs @@ -71,10 +71,10 @@ use crate::error::{ self, AlterExprToRequestSnafu, CatalogSnafu, ColumnDataTypeSnafu, ColumnNotFoundSnafu, ConvertSchemaSnafu, CreateLogicalTablesSnafu, CreateTableInfoSnafu, DeserializePartitionSnafu, EmptyDdlExprSnafu, ExtractTableNamesSnafu, FlowNotFoundSnafu, InvalidPartitionRuleSnafu, - InvalidPartitionSnafu, InvalidTableNameSnafu, InvalidViewNameSnafu, InvalidViewStmtSnafu, - ParseSqlValueSnafu, Result, SchemaInUseSnafu, SchemaNotFoundSnafu, SchemaReadOnlySnafu, - SubstraitCodecSnafu, TableAlreadyExistsSnafu, TableMetadataManagerSnafu, TableNotFoundSnafu, - UnrecognizedTableOptionSnafu, ViewAlreadyExistsSnafu, + InvalidPartitionSnafu, InvalidSqlSnafu, InvalidTableNameSnafu, InvalidViewNameSnafu, + InvalidViewStmtSnafu, ParseSqlValueSnafu, Result, SchemaInUseSnafu, SchemaNotFoundSnafu, + SchemaReadOnlySnafu, SubstraitCodecSnafu, TableAlreadyExistsSnafu, TableMetadataManagerSnafu, + TableNotFoundSnafu, UnrecognizedTableOptionSnafu, ViewAlreadyExistsSnafu, }; use crate::expr_factory; use crate::statement::show::create_partitions_stmt; @@ -465,6 +465,12 @@ impl StatementExecutor { expr: CreateViewExpr, ctx: QueryContextRef, ) -> Result { + ensure! { + !(expr.create_if_not_exists & expr.or_replace), + InvalidSqlSnafu { + err_msg: "syntax error Create Or Replace and If Not Exist cannot be used together", + } + }; let _timer = crate::metrics::DIST_CREATE_VIEW.start_timer(); let schema_exists = self diff --git a/tests/cases/standalone/common/view/show_create.result b/tests/cases/standalone/common/view/show_create.result index 9960afc9609d..4b0249b3bd9c 100644 --- a/tests/cases/standalone/common/view/show_create.result +++ b/tests/cases/standalone/common/view/show_create.result @@ -97,26 +97,23 @@ SELECT * FROM v1; --- if not exists with replace, so it changes --- CREATE OR REPLACE VIEW IF NOT EXISTS v1 AS SELECT c FROM t1; -Affected Rows: 0 +Error: 1004(InvalidArguments), Invalid SQL, error: syntax error Create Or Replace and If Not Exist cannot be used together SHOW CREATE VIEW v1; -+------+-------------------------------------------------------------+ -| View | Create View | -+------+-------------------------------------------------------------+ -| v1 | CREATE OR REPLACE VIEW IF NOT EXISTS v1 AS SELECT c FROM t1 | -+------+-------------------------------------------------------------+ ++------+------------------------------------------------------------------+ +| View | Create View | ++------+------------------------------------------------------------------+ +| v1 | CREATE OR REPLACE VIEW v1 AS SELECT a, b, c FROM t1 WHERE a > 43 | ++------+------------------------------------------------------------------+ SELECT * FROM v1; -+-------------------------+ -| c | -+-------------------------+ -| 1970-01-01T00:00:00.001 | -| 1970-01-01T00:00:00.002 | -| 1970-01-01T00:00:00.003 | -| 1970-01-01T00:00:00.004 | -+-------------------------+ ++----+------------+-------------------------+ +| a | b | c | ++----+------------+-------------------------+ +| 44 | greptimedb | 1970-01-01T00:00:00.004 | ++----+------------+-------------------------+ DROP VIEW v1;