All skills
clickhouse avatar

/clickhouse-js-node-troubleshooting

@faa5b11 official
by clickhouseclickhouse/agent-skills543 stars
39

Troubleshoot and resolve common issues with the ClickHouse Node.js client (@clickhouse/client). Use this skill whenever a user reports errors, unexpected behavior, or configuration questions involving the Node.js client specifically — including socket hang-up errors, Keep-Alive problems, stream handling issues, data type mismatches, read-only user restrictions, proxy/TLS setup problems, or long-running query timeouts. Trigger even when the user hasn't precisely named the issue; vague symptoms like "my inserts keep failing" or "connection drops randomly" in a Node.js context are strong signals to use this skill. Do NOT use for browser/Web client issues.

Use this Skill: https://skilld.dev/gh/clickhouse/agent-skills/clickhouse-js-node-troubleshooting

This session only. Nothing lands on disk.

referencedata-types.md

≈1.3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Data Type Mismatches

Large integers returned as strings

Applies to: all versions. The output_format_json_quote_64bit_integers ClickHouse setting is server-side and can be passed via clickhouse_settings in any client version.

UInt64, Int64, UInt128, Int128, UInt256, Int256 are serialized as strings in JSON* formats to prevent overflow (they exceed Number.MAX_SAFE_INTEGER).

To receive them as numbers (use with caution — precision loss possible):

const resultSet = await client.query({
  query: "SELECT toUInt64(9007199254740993)",
  format: "JSONEachRow",
  clickhouse_settings: { output_format_json_quote_64bit_integers: 0 },
});

Tip (>= 1.15.0): BigInt values are now supported in query parameters, so you can safely pass large integers as bind params without string workarounds.

Decimals losing precision on read

Applies to: all versions (this is a ClickHouse JSON serialization behavior). For custom JSON parse/stringify (e.g., using a BigInt-safe parser), see >= 1.14.0 which added configurable json.parse and json.stringify functions.

ClickHouse returns Decimals as numbers by default in JSON* formats. Cast to string in the query:

const resultSet = await client.query({
  query: `
    SELECT toString(my_decimal) AS my_decimal
    FROM my_table
  `,
  format: "JSONEachRow",
});

When inserting, always use the string representation to avoid precision loss:

await client.insert({
  table: "my_table",
  values: [{ dec64: "123456789123456.789" }],
  format: "JSONEachRow",
});

Inserting a UUID into a UInt128 column fails (CANNOT_PARSE_INPUT_ASSERTION_FAILED)

Applies to: all versions. This is a ClickHouse input-parsing behavior, not a client bug.

ClickHouse converts a UUID into UInt128 implicitly only for the VALUES clause. With the row-oriented JSON formats the client uses (e.g. JSONEachRow), sending a UUID string such as '019982cb-3abf-7e12-9668-c788a9e3639c' for a UInt128 column fails with CANNOT_PARSE_INPUT_ASSERTION_FAILED.

Fix it with one of two patterns:

Pattern 1 — convert the UUID on the client and send it as a decimal string (recommended). A JS number cannot hold 128 bits without precision loss, so always pass UInt128 as a string:

import * as crypto from "node:crypto";

function uuidToUInt128(uuid) {
  // 8-4-4-4-12 hex digits → 32 hex digits → BigInt → decimal string
  return BigInt("0x" + uuid.replace(/-/g, "")).toString();
}

const uuid = crypto.randomUUID();
await client.insert({
  table: "events",
  format: "JSONEachRow",
  values: [{ id: uuidToUInt128(uuid), description: "converted on the client" }],
});

Read UInt128 back with toString(id) in the SELECT to avoid the same precision loss.

Pattern 2 — declare the UUID column as EPHEMERAL and let ClickHouse populate the UInt128 column via its DEFAULT expression. The ephemeral column must be listed in columns so the DEFAULT is evaluated:

// CREATE TABLE events (id UInt128 DEFAULT id_uuid, id_uuid UUID EPHEMERAL, description String) ...
await client.insert({
  table: "events",
  format: "JSONEachRow",
  values: [{ id_uuid: uuid, description: "populated via EPHEMERAL column" }],
  columns: ["id_uuid", "description"],
});

Format Selection Quick Reference

Use case Recommended format Min version
Insert/select JS objects JSONEachRow all
Bulk insert arrays JSONEachRow all
Stream large result sets JSONEachRow, JSONCompactEachRow all
CSV file streaming CSV, CSVWithNames all
Parquet file streaming Parquet >= 0.2.6
Single JSON object response JSON, JSONCompact JSON all; JSONCompact >= 0.0.14
Stream with progress JSONEachRowWithProgress >= 1.7.0

⚠️ JSON and JSONCompact return a single object and cannot be streamed.

Date/DateTime insertion fails or produces wrong values

Applies to: all versions. Note that >= 0.2.1 changed Date object serialization to use time-zone-agnostic Unix timestamps instead of timezone-naive datetime strings, which fixed timezone mismatch issues between client and server.

  • Date / Date32 columns accept strings only (e.g., '2024-01-15').
  • DateTime / DateTime64 columns accept strings or JS Date objects. To use Date objects, set:
import { createClient } from "@clickhouse/client";
const client = createClient({
  clickhouse_settings: { date_time_input_format: "best_effort" },
});

Source: SKILL.md on GitHub

No alerts17d3 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    This skill provides comprehensive troubleshooting documentation for the ClickHouse Node.js client. It includes security best practices, such as using parameterized queries to prevent SQL injection and clear warnings against insecure TLS configurations in production environments. No malicious patterns or security risks were detected.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

Signed by skilld at faa5b11. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 days ago.

Activeupdated 3 months ago
  • clickhouse
  • nodejs
  • troubleshooting
  • client
  • socket
  • tls
  • compression
  • data-types
  • connection

README badge

README badge for clickhouse/agent-skills/clickhouse-js-node-troubleshooting

Diagnose and resolve common issues with the ClickHouse Node.js client (@clickhouse/client), including socket hang-ups, data type mismatches, TLS configuration problems, compression failures, and read-only user restrictions. Applies only to Node.js runtime environments, not browser or edge runtimes.

Generated from the current SKILL.md.

Does this skill work with the browser/Web client or just Node.js?
This skill covers only the Node.js runtime (@clickhouse/client), including Next.js Node API routes and Server Actions. For browser, Edge runtime, Cloudflare Workers, or Web Worker environments, use @clickhouse/client-web instead.
What kinds of errors does this skill help troubleshoot?
Socket hang-ups, ECONNRESET, data type mismatches, read-only user restrictions, proxy/TLS setup, compression issues, query timeouts, and query parameter interpolation problems with the ClickHouse Node.js client.
Do I need to know the exact error message to use this skill?
No. Vague symptoms like 'my inserts keep failing' or 'connection drops randomly' in a Node.js context are strong enough signals to trigger this skill.
Will this skill help with version compatibility issues?
Yes. The skill flags if a fix requires a minimum client version and will ask for your version if it's needed to recommend the right solution.

Generated from the current SKILL.md. These answers refresh after source changes.