Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClickHouse create temporary table

Tags:

clickhouse

I have an issue when I am trying to create a temporary table in ClickHouse. I execute simple query and get an error

create TEMPORARY TABLE nn1 as select 1;

message: Code: 113, e.displayText() = DB::Exception: There is no session, e.what() = DB::Exception

Is someone know why it happen and how to solve the issue? I suppos I need start session before doing the query but I don't know how to do this.

I am trying to doing this using ClickHouse's interface for making query. It looks like

enter image description here

like image 270
Nik Avatar asked Oct 17 '25 16:10

Nik


1 Answers

By default all queries done via HTTP interface are stateless.

To use temporary tables you need to have an active session. It's enough to add session_id parameter with some value to the URL of ClickHouse request.

So for example:
replace http://127.0.0.1:8123/
to http://127.0.0.1:8123/?session_id=mysession

Later requests with the same session_id will 'remember' temporary tables, settings, etc. you did in previous queries with that session_id.

Please also remember that sessions use exclusive locks, so you can't run 2 requests with the same session_id concurrently. And by default session lifetime equals 60 seconds, but can be adjusted.

Check the official documentation https://clickhouse.yandex/docs/en/interfaces/http/

like image 89
filimonov Avatar answered Oct 19 '25 13:10

filimonov