【问题标题】:How to make an HTTP request to get data from clickhouse database如何发出 HTTP 请求以从 clickhouse 数据库中获取数据
【发布时间】:2023-03-06 13:05:01
【问题描述】:

我正在尝试发出 HTTP 请求以使用 Go 从 clickhouse 数据库中获取数据。我对它没有太多经验,不知道如何通过查询获取返回值

这就是我所拥有的:

reader := strings.NewReader("SELECT COUNT(*) FROM system.tables WHERE database = 'local' AND name = 'persons'")
request, err := http.NewRequest("GET", "http://localhost:8123", reader)
if err != nil {
    fmt.Println(err)
}

client := &http.Client{}
resp, err := client.Do(request)
if err != nil {
    fmt.Println(err)
}

fmt.Println("The answer is: ", resp.Body)

预期的输出应该是一个数字(1 表示表存在,0 表示不存在)但我得到了resp.Body 这个输出:

The answer is:  &{0xc4201741c0 {0 0} false <nil> 0x6a9bb0 0x6a9b20}

有什么办法只获取查询的值吗?

【问题讨论】:

标签: database go clickhouse


【解决方案1】:

我不得不多加一行

message, _ := ioutil.ReadAll(resp.Body)

fmt.Println(string(message))

这帮助我得到了我想要的。

【讨论】:

    猜你喜欢
    • 2018-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 2013-11-01
    • 1970-01-01
    • 2017-10-24
    相关资源
    最近更新 更多