Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions datafusion/sql/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2435,17 +2435,23 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
span: _,
}) = val
{
let name =
name.replace('$', "").parse::<usize>().map_err(|_| {
plan_datafusion_err!("Can't parse placeholder: {name}")
})? - 1;
let index = match name[1..].parse::<usize>().map_err(|_| {
plan_datafusion_err!("Can't parse placeholder: {name}")
})? {
0 => {
return plan_err!(
"Invalid placeholder, zero is not a valid index: {name}"
);
}
index => index - 1,
};
let field = fields.get(idx).ok_or_else(|| {
plan_datafusion_err!(
"Placeholder ${} refers to a non existent column",
idx + 1
)
})?;
let _ = prepare_param_data_types.insert(name, Arc::clone(field));
let _ = prepare_param_data_types.insert(index, Arc::clone(field));
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions datafusion/sqllogictest/test_files/insert_values_placeholders.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

##########
## INSERT VALUES placeholder tests
##########

statement ok
CREATE TABLE placeholder_zero_insert(x BIGINT NULL);

query error DataFusion error: Error during planning: Invalid placeholder, zero is not a valid index: \$0
EXPLAIN INSERT INTO placeholder_zero_insert VALUES ($0);