ClickHouse-Net icon indicating copy to clipboard operation
ClickHouse-Net copied to clipboard

System.NotSupportedException:“Unknown column type Decimal(9, 4)”

Open chenhunhun opened this issue 1 year ago • 3 comments

Description

CLICKHOUSE FIELD IS DEFINED LIKE THIS: PrintTicketLimitMoney Nullable(Decimal(9, 4)), When i try to insert row: foreach (DataRow row in table.Rows) { insertCommand.Parameters.Clear();

                                foreach (DataColumn column in table.Columns)
                                {
                                    string paramName = $"{column.ColumnName}";
                                    object columnValue = row[column.ColumnName];
                                    insertCommand.Parameters.Add(paramName, columnValue ?? DBNull.Value);
                                }

                     
                                insertCommand.ExecuteNonQuery();//get  error
                            }

... System.NotSupportedException:“Unknown column type Decimal(9, 4)”

how to solve it.

chenhunhun avatar Feb 29 '24 15:02 chenhunhun

Check the library version you use. Fixed length Decimal is supported since 1.1.15, since 1.2.3 they have improved precision (although still only fixed lengths are supported), support for arbitrary precision decimals came in 1.4.0 and after that they didn't change.

killwort avatar Feb 29 '24 17:02 killwort

Plus, as far as I see you're doing inserts row-by-row, which is completely wrong for Clickhouse. Consider switching to bulk inserts.

And if you still encounted errors in most recent library versions, please provide table deifnition (CREATE command you used), and failing command text too.

killwort avatar Feb 29 '24 17:02 killwort

Thanks your answer! for more table in my sqlserver, i read your readme.md about the bulk function like var command=connection.CreateCommand(); command.CommandText="INSERT INTO test (date,time,str,int) VALUES @bulk"; command.Parameters.Add(new ClickHouseParameter{ ParameterName="bulk", Value=list }); command.ExecuteNonQuery();

now i want to use like BulkInsert(DataTable, tableName), not want to define more class T.

how to solve it.

Plus, as far as I see you're doing inserts row-by-row, which is completely wrong for Clickhouse. Consider switching to bulk inserts.

And if you still encounted errors in most recent library versions, please provide table deifnition (CREATE command you used), and failing command text too.

chenhunhun avatar Mar 01 '24 10:03 chenhunhun