ClickHouse Cloud quick start

You can use the familiar [`INSERT INTO TABLE`](/docs/sql-reference/statements/insert-into) command with ClickHouse, but it is important to understand that each insert into a [`MergeTree`](/docs/engines/table-engines/mergetree-family/mergetree) table causes a **part** to be created in storage.

ClickHouse best practice

Insert a large number of rows per batch - tens of thousands or even millions of
rows at once. Don't worry - ClickHouse can easily handle that type of volume - and it will [save you money](/docs/best-practices/selecting-an-insert-strategy#batch-inserts-if-synchronous) by sending fewer write requests to your service.

  

Even for a simple example, let's insert more than one row at a time:

```
INSERT INTO helloworld.my_first_table (user_id, message, timestamp, metric) VALUES
    (101, 'Hello, ClickHouse!',                                 now(),       -1.0    ),
    (102, 'Insert a lot of rows per batch',                     yesterday(), 1.41421 ),
    (102, 'Sort your data based on your commonly-used queries', today(),     2.718   ),
    (101, 'Granules are the smallest chunks of data read',      now() + 5,   3.14159 )
```

Note

Notice the `timestamp` column is populated using various [**Date**](/docs/sql-reference/data-types/date) and [**DateTime**](/docs/sql-reference/data-types/datetime) functions. ClickHouse has hundreds of useful functions that you can [view in the **Functions** section](/docs/sql-reference/functions).

Let's verify it worked:

```
SELECT * FROM helloworld.my_first_table
```

### Add data using the ClickHouse Client[​](#add-data-using-the-clickhouse-client "Direct link to Add data using the ClickHouse Client")

You can also connect to your ClickHouse Cloud service using a command-line tool named [**clickhouse client**](/docs/interfaces/cli). Click `Connect` on the left menu to access these details. From the dialog select `Native` from the drop-down:  

1. Install [ClickHouse](/docs/interfaces/cli).
2. Run the command, substituting your hostname, username, and password:

```
./clickhouse client --host HOSTNAME.REGION.CSP.clickhouse.cloud \
--secure --port 9440 \
--user default \
--password <password>
```

If you get the smiley face prompt, you're ready to run queries!

```
:)
```

3. Give it a try by running the following query:

  

```
SELECT *
FROM helloworld.my_first_table
ORDER BY timestamp
```

Notice the response comes back in a nice table format:

```
┌─user_id─┬─message────────────────────────────────────────────┬───────────timestamp─┬──metric─┐
│     102 │ Insert a lot of rows per batch                     │ 2022-03-21 00:00:00 │ 1.41421 │
│     102 │ Sort your data based on your commonly-used queries │ 2022-03-22 00:00:00 │   2.718 │
│     101 │ Hello, ClickHouse!                                 │ 2022-03-22 14:04:09 │      -1 │
│     101 │ Granules are the smallest chunks of data read      │ 2022-03-22 14:04:14 │ 3.14159 │
└─────────┴────────────────────────────────────────────────────┴─────────────────────┴─────────┘

4 rows in set. Elapsed: 0.008 sec.
```

4. Add a [`FORMAT`](/docs/sql-reference/statements/select/format) clause to specify one of the [many supported output formats of ClickHouse](/docs/interfaces/formats):

  

```
SELECT *
FROM helloworld.my_first_table
ORDER BY timestamp
FORMAT TabSeparated
```

In the above query, the output is returned as tab-separated:

```
Query id: 3604df1c-acfd-4117-9c56-f86c69721121

102 Insert a lot of rows per batch      2022-03-21 00:00:00     1.41421
102 Sort your data based on your commonly-used queries  2022-03-22 00:00:00     2.718
101 Hello, ClickHouse!  2022-03-22 14:04:09     -1
101 Granules are the smallest chunks of data read       2022-03-22 14:04:14     3.14159

4 rows in set. Elapsed: 0.005 sec.
```

5. To exit the `clickhouse client`, enter the **exit** command:

  

```
exit
```

### Upload a File[​](#upload-a-file "Direct link to Upload a File")

A common task when getting started with a database is to insert some data that you already have in files. We have some
sample data online that you can insert that represents clickstream data - it includes a user ID, a URL that was visited, and
the timestamp of the event.

Suppose we have the following text in a CSV file named `data.csv`:

```
102,This is data in a file,2022-02-22 10:43:28,123.45
101,It is comma-separated,2022-02-23 00:00:00,456.78
103,Use FORMAT to specify the format,2022-02-21 10:43:30,678.90
```

1. The following command inserts the data into `my_first_table`:

  

```
./clickhouse client --host HOSTNAME.REGION.CSP.clickhouse.cloud \
--secure --port 9440 \
--user default \
--password <password> \
--query='INSERT INTO helloworld.my_first_table FORMAT CSV' < data.csv
```

2. Notice the new rows appear in the table now if querying from the SQL console:

IP access list filtering

Before you move on, we recommended setting up IP access list filtering.
See ["Setting IP filters"](/docs/cloud/security/setting-ip-filters) for more details.

## What's Next?[​](#whats-next "Direct link to What's Next?")

- The [Tutorial](/docs/tutorial) has you insert 2 million rows into a table and write some analytical queries
- We have a list of [example datasets](/docs/getting-started/example-datasets) with instructions on how to insert them
- Check out our 25-minute video on [Getting Started with ClickHouse](https://clickhouse.com/company/events/getting-started-with-clickhouse/)
- If your data is coming from an external source, view our [collection of integration guides](/docs/integrations) for connecting to message queues, databases, pipelines and more
- If you're using a UI/BI visualization tool, view the [user guides for connecting a UI to ClickHouse](/docs/integrations/data-visualization)
- The user guide on [primary keys](/docs/guides/best-practices/sparse-primary-indexes) is everything you need to know about primary keys and how to define them

- [Create a ClickHouse service](#1-create-a-clickhouse-service)- [Connect to ClickHouse](#2-connect-to-clickhouse)
    - [Connect using SQL console](#connect-using-sql-console)- [Connect with your app](#connect-with-your-app)- [Add data](#3-add-data)
      - [ClickPipes](#clickpipes)- [Add data using the SQL Console](#add-data-using-the-sql-console)- [Add data using the ClickHouse Client](#add-data-using-the-clickhouse-client)- [Upload a File](#upload-a-file)- [What's Next?](#whats-next)

Was this page helpful?