url.md 1.7 KB
Newer Older
I
Ivan Blinkov 已提交
1 2 3 4 5
---
toc_priority: 41
toc_title: url
---

6
# url {#url}
7

O
Olga Revyakina 已提交
8
`url` function creates a table from the `URL` with given `format` and `structure`.
9

O
Fixes  
Olga Revyakina 已提交
10
`url` function may be used in `SELECT` and `INSERT` queries on data in [URL](../../engines/table-engines/special/url.md) tables.
11

O
Olga Revyakina 已提交
12
**Syntax**
13

O
Olga Revyakina 已提交
14 15 16 17
``` sql
url(URL, format, structure)
```

D
Dmitriy 已提交
18
**Parameters**
O
Olga Revyakina 已提交
19

D
Dmitriy 已提交
20
- `URL` — HTTP or HTTPS server address, which can accept `GET` or `POST` queries (for `SELECT` or `INSERT` queries correspondingly). Type: [String](../../sql-reference/data-types/string.md).
D
Dmitriy 已提交
21 22
- `format`[Format](../../interfaces/formats.md#formats) of the data. Type: [String](../../sql-reference/data-types/string.md).
- `structure` — Table structure in `'UserID UInt64, Name String'` format. Determines column names and types. Type: [String](../../sql-reference/data-types/string.md).
O
Olga Revyakina 已提交
23 24 25

**Returned value**

D
Dmitriy 已提交
26
A table with the specified format and structure and with data from the defined `URL`.
O
Olga Revyakina 已提交
27 28 29

**Examples**

D
Dmitriy 已提交
30
Getting the first 3 lines of a table that contains columns of `String` and [UInt32](../../sql-reference/data-types/int-uint.md) type from HTTP-server which answers in [CSV](../../interfaces/formats.md/#csv) format.
O
Olga Revyakina 已提交
31 32 33 34

``` sql
SELECT * FROM url('http://127.0.0.1:12345/', CSV, 'column1 String, column2 UInt32') LIMIT 3;
```
35

D
Dmitriy 已提交
36
Inserting data from a `URL` into a table:
37

38
``` sql
O
olgarev 已提交
39 40 41
CREATE TABLE test_table (column1 String, column2 UInt32) ENGINE=Memory;
INSERT INTO FUNCTION url('http://127.0.0.1:8123/?query=INSERT+INTO+test_table+FORMAT+CSV', 'CSV', 'column1 String, column2 UInt32') VALUES ('http interface', 42);
SELECT * FROM test_table;
42
```
I
Ivan Blinkov 已提交
43

O
Olga Revyakina 已提交
44
[Original article](https://clickhouse.tech/docs/en/sql-reference/table-functions/url/) <!--hide-->