Comments (5)
Nope, query parser in driver does not support such syntax.
By the way, you have control over parameter type/value, why do you need explicit cast?
And, as clickhouse documentation states, you shouldn't use one-row inserts, check info in https://github.com/killwort/ClickHouse-Net#hidden-bulk-insert-functionality here for more efficient way of inserting.
from clickhouse-net.
@killwort
I want to import rows from Postgres
select OrderId, IsFirstOrder from orders
and export to ClickHouse
insert into FactOrder (OrderId, IsFirstOrder) values @bulk
Both database has boolean db type for IsFirstOrder.
But in c# code IsFirstOrder has different db types: Boolean in postgres and DbByte in clickhouse.
System.InvalidCastException: 'Unable to cast object of type 'System.Boolean' to type 'System.SByte'.'
Read from Postgres
using (var dataReader = cmd.ExecuteReader())
{
while (dataReader.Read())
{
var row = new Dictionary<string, object>();
for (var fieldCount = 0; fieldCount < dataReader.FieldCount; fieldCount++)
{
row.Add(dataReader.GetName(fieldCount), dataReader[fieldCount]);
}
yield return row;
}
}
write to ClickHouse
using (var cmd = db.CreateCommand())
{
cmd.CommandText = sql;
if (cmd.Connection.State != ConnectionState.Open) { cmd.Connection.Open(); }
if (@params != null)
foreach (KeyValuePair<string, object> p in @params)
{
IDbDataParameter dbParameter = cmd.CreateParameter();
dbParameter.ParameterName = p.Key;
dbParameter.Value = p.Value;
cmd.Parameters.Add(dbParameter);
}
return cmd.ExecuteNonQuery();
}
How I can cast postgres:boolean to clickhouse:boolean in this case?
from clickhouse-net.
When you implement IEnumerable interface in your object, do casts on return, like that:
class MyDataObject:IEnumerable{
public bool SomeBooleanFieldStoredInUInt8{get;set;}
....
public IEnumerator GetEnumerator(){
....
yield return SomeBooleanFieldStoredInUInt8?(byte)1:(byte)0;
....
}
}
from clickhouse-net.
the idea is that all the code should be in sql, and c # does not know what data will be there, c # code can only call DbCommand for reading and writing.
from clickhouse-net.
I think it may be a part of your sdk.
DBNull -> (object)null
Bool => sbyte
from clickhouse-net.
Related Issues (20)
- Any Way To optimize the ClickHouseCommand memory Use HOT 1
- how to set timezone in current connect HOT 3
- Driver hangs when inserting into ReplicatedMergeTree tables HOT 6
- Connection string for cluster db
- Inserting multiple rows doesn't work returns an timeout error HOT 4
- Please add a English and Russian headings in documentation / readme.md HOT 1
- Replace sql parameter error when execute sql HOT 1
- DataTable.Load(DbDataReader) has a wrong hadppend Can't use it in this way? HOT 3
- Пул подключений к БД HOT 1
- System.NotSupportedException:“Unknown column type Decimal(9, 4)” HOT 3
- find a bug ,when process nullable(DateTime) fields
- ClickHouseConnection how to use it properly HOT 1
- how to get correct value from datetime64 ? HOT 1
- DialogueLock of ClickhouseConnection is not released when read command fails and the reader is not created (the method dispose of the reader do the release when it's at least created) HOT 1
- Json Column types are not supported
- Special Character and connect string requirements HOT 1
- Type LowCardinality(Nullable(String)) not supported in v2.0.5 HOT 1
- Best way to measure write performance of batch insertion
- No rows returned in select statement, though data is present in the table HOT 1
- INSERT ... SETTINGS syntax does not work with bulk insertion
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clickhouse-net.