Search code examples
databaseclickhouseclickhouse-client

Cat with --multiquery is not working when creating and inserting data into Temporary table clickhouse


I am running multiple queries using one session. I have to create a Temporary table and then I have to insert data from CSV to that file and after that, I have to insert data into a Permanent table. I have to run all of these queries in one session. But I am getting an Error. This is my query:

cat ./files/File.txt | clickhouse-client --multiquery --format_csv_delimiter="," --query="CREATE TEMPORARY TABLE IF NOT EXISTS temp_table(col0 String,col1 String,col2 String,col3 String) ; INSERT INTO temp_table FORMAT CSV ; INSERT INTO prmanent_table(person_1,person_2,timestamp_,duration) select col0 as person_1,col1 as person_2,col2 as timestamp_,col3 as duration from temp_table ; "

Error

Code: 117. DB::Exception: Expected end of line: (at row 1)

Row 1:
Column 0,   name: col0, type: String, parsed text: "; INSERT INTO prmanent_table(person_1"
Column 1,   name: col1, type: String, parsed text: "person_2"
Column 2,   name: col2, type: String, parsed text: "timestamp_"
Column 3,   name: col3, type: String, parsed text: "duration) select col0 as person_1"
ERROR: There is no line feed. "c" found instead.
 It's like your file has more columns than expected.
And if your file have right number of columns, maybe it have unquoted string value with comma.```

Solution

  • use FROM INFILE

    INSERT INTO TABLE temp_table FROM INFILE './files/File.txt' format CSV;