2020-04-08 14:22:25 +00:00
|
|
|
|
---
|
2022-08-26 19:07:59 +00:00
|
|
|
|
slug: /zh/sql-reference/table-functions/url
|
2022-04-10 23:08:18 +00:00
|
|
|
|
sidebar_position: 41
|
|
|
|
|
sidebar_label: url
|
2020-04-08 14:22:25 +00:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# url {#url}
|
|
|
|
|
|
2021-03-19 02:32:20 +00:00
|
|
|
|
`url` 函数从 `URL` 创建一个具有给定 `format` 和 `structure` 的表。
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
2021-03-19 02:32:20 +00:00
|
|
|
|
`url` 函数可用于对[URL](../../engines/table-engines/special/url.md)表中的数据进行 `SELECT` 和 `INSERT` 的查询中。
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
2021-03-19 02:32:20 +00:00
|
|
|
|
**语法**
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
2021-03-19 02:32:20 +00:00
|
|
|
|
``` sql
|
|
|
|
|
url(URL, format, structure)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**参数**
|
|
|
|
|
|
|
|
|
|
- `URL` — HTTP或HTTPS服务器地址,它可以接受 `GET` 或 `POST` 请求 (对应于 `SELECT` 或 `INSERT` 查询)。类型: [String](../../sql-reference/data-types/string.md)。
|
|
|
|
|
- `format` — 数据[格式](../../interfaces/formats.md#formats)。类型: [String](../../sql-reference/data-types/string.md)。
|
|
|
|
|
- `structure` — 以 `'UserID UInt64, Name String'` 格式的表结构。确定列名和类型。 类型: [String](../../sql-reference/data-types/string.md)。
|
|
|
|
|
|
|
|
|
|
**返回值**
|
|
|
|
|
|
|
|
|
|
A table with the specified format and structure and with data from the defined `URL`.
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
|
|
|
|
**示例**
|
|
|
|
|
|
2021-03-19 02:32:20 +00:00
|
|
|
|
获取一个表的前3行,该表是从HTTP服务器获取的包含 `String` 和 [UInt32](../../sql-reference/data-types/int-uint.md) 类型的列,以[CSV](../../interfaces/formats.md#csv)格式返回。
|
|
|
|
|
|
2020-04-08 14:22:25 +00:00
|
|
|
|
``` sql
|
2021-03-19 02:32:20 +00:00
|
|
|
|
SELECT * FROM url('http://127.0.0.1:12345/', CSV, 'column1 String, column2 UInt32') LIMIT 3;
|
2020-04-08 14:22:25 +00:00
|
|
|
|
```
|
|
|
|
|
|
2021-03-19 02:32:20 +00:00
|
|
|
|
将 `URL` 的数据插入到表中:
|
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
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;
|
|
|
|
|
```
|
2023-05-01 13:40:14 +00:00
|
|
|
|
## 虚拟列 {#virtual-columns}
|
|
|
|
|
|
|
|
|
|
- `_path` — `URL`路径。
|
|
|
|
|
- `_file` — 资源名称。
|
|
|
|
|
|
|
|
|
|
**另请参阅**
|
|
|
|
|
|
|
|
|
|
- [虚拟列](https://clickhouse.com/docs/en/operations/table_engines/#table_engines-virtual_columns)
|