Giorgi / DuckDB.NET

Bindings and ADO.NET Provider for DuckDB
https://duckdb.net
MIT License
338 stars 61 forks source link

version 1.0 Binder Error: Referenced column "x" not found in FROM clause! #193

Closed jp200k closed 2 weeks ago

jp200k commented 3 weeks ago

When using DuckDB 1.0 in C#, I got the following error: Binder Error: Referenced column "city" not found in FROM clause! LINE 1: ..._lo, temp_hi, prcp, date, id) VALUES (@city, @temp_lo, @temp_hi, @prcp, @date,...

my statement is: INSERT INTO weather (city, temp_lo, temp_hi, prcp, date, id) VALUES (@city, @temp_lo, @temp_hi, @prcp, @date, @id ); where the DuckDBParameter are all correctly assigned, including ParameterName, SourceColumn, DateType and Value.

If NOT using parameters and hard coding above insert statement, it works well. When using parameters, I got above error. Searching the web, I found other users got similar error message but their causes might be different. However, here the "FROM clause" is not relative.

Thank you for your hard work.

Giorgi commented 2 weeks ago

@jp200k Can you format the code as a code snippet? It's hard to read now.

Cricle commented 2 weeks ago

According to duckdb doc prepared_statements, no start with @ paramter accept. Can you try to use like $city? @jp200k

brendonparker commented 2 weeks ago

This is a common scenario people run into (including myself). As @Cricle stated, the parameters need to be prefixed with $ not @. Otherwise you get the referenced error, which is a little misleading.

@jp200k so instead of:

INSERT INTO weather (city, temp_lo, temp_hi, prcp, date, id) 
VALUES (@city, @temp_lo, @temp_hi, @prcp, @Date, @id);

try:

INSERT INTO weather (city, temp_lo, temp_hi, prcp, date, id) 
VALUES ($city, $temp_lo, $temp_hi, $prcp, $Date, $id);
Giorgi commented 2 weeks ago

@brendonparker Thanks for confirming that this is not a DuckDB.NET issues. This is documented in the docs: https://duckdb.net/docs/basic-usage.html#parameterized-statements