---
name: clickhouse_open
kind: function
lang: go
domain: infra
version: "1.0.0"
purity: impure
signature: "func ClickHouseOpen(host string, port int, user, password, database string) (*sql.DB, error)"
description: "Conecta a ClickHouse construyendo DSN clickhouse://user:pass@host:port/database."
tags: [database, clickhouse, connection, sql, olap]
uses_functions: []
uses_types: [db_config_go_infra]
returns: []
returns_optional: false
error_type: "error_go_core"
imports: ["database/sql", "github.com/ClickHouse/clickhouse-go/v2"]
params:
  - name: host
    desc: "hostname del servidor ClickHouse"
  - name: port
    desc: "puerto de ClickHouse (9000 para protocolo nativo, 8123 para HTTP)"
  - name: user
    desc: "nombre de usuario para autenticacion"
  - name: password
    desc: "contraseña para autenticacion"
  - name: database
    desc: "nombre de la base de datos a conectar"
output: "conexion sql.DB abierta a ClickHouse con ping verificado"
tested: false
tests: []
test_file_path: ""
file_path: "functions/infra/clickhouse_open.go"
---

## Ejemplo

```go
db, err := ClickHouseOpen("localhost", 9000, "default", "", "analytics")
if err != nil {
    log.Fatal(err)
}
defer DBClose(db)

rows, err := DBQuery(db, "SELECT event, count() FROM events GROUP BY event")
```

## Notas

Usa el driver `github.com/ClickHouse/clickhouse-go/v2` registrado como "clickhouse". Puerto por defecto de ClickHouse es 9000 (nativo) o 8123 (HTTP). Hace ping al abrir para verificar conectividad.
