---
title: How to debug types
meta:
  description: Tools and techniques for debugging data types in ClickHouse and Tinybird.
---

# How to debug types

Tools and techniques for debugging data types in ClickHouse and Tinybird.

## Using toTypeName()

### Check column types

**Use case**: See what type ClickHouse assigned to a column

**Example**:
```sql
-- Check type of specific column
SELECT toTypeName(user_id) as user_id_type FROM events LIMIT 1

-- Check types of all columns
SELECT
  toTypeName(id) as id_type,
  toTypeName(user_id) as user_id_type,
  toTypeName(value) as value_type,
  toTypeName(timestamp) as timestamp_type
FROM events
LIMIT 1
```

### Check expression types

**Use case**: See what type an expression evaluates to

**Example**:
```sql
-- Check type of computed expression
SELECT toTypeName(user_id + 1) as computed_type FROM events LIMIT 1
```

## Using toTypeName() with sample data

### Examine data and types together

**Use case**: See both the data and its inferred type

**Example**:
```sql
-- See data and its type
SELECT
  user_id,
  toTypeName(user_id) as type,
  length(toString(user_id)) as length
FROM events
LIMIT 10
```

### Debug type conversion issues

**Use case**: Understand why type conversions fail

**Example**:
```sql
-- Check what types are being converted
SELECT
  original_column,
  toTypeName(original_column) as original_type,
  toUInt32OrNull(original_column) as converted_value,
  toTypeName(toUInt32OrNull(original_column)) as converted_type
FROM events
LIMIT 10
```

## Schema debugging

### Check table schema

**Use case**: See the actual schema of a table

**Example**:
```sql
-- Get table schema
DESCRIBE TABLE events

-- Or use system.columns
SELECT
  name,
  type,
  default_expression
FROM system.columns
WHERE table = 'events'
```

### Compare expected vs actual types

**Use case**: Verify if schema matches expectations

**Example**:
```sql
-- Check if types match expectations
SELECT
  name,
  type,
  CASE
    WHEN type = 'UInt32' THEN 'Expected'
    WHEN type = 'String' THEN 'Unexpected - should be UInt32'
    ELSE 'Check this type'
  END as status
FROM system.columns
WHERE table = 'events'
```

## Data validation

### Check for type inconsistencies

**Use case**: Find data that doesn't match expected type

**Example**:
```sql
-- Find non-numeric values in numeric column
SELECT
  user_id,
  toTypeName(user_id) as type
FROM events
WHERE toUInt32OrNull(user_id) IS NULL
LIMIT 10
```

### Validate date formats

**Use case**: Check if date strings can be parsed

**Example**:
```sql
-- Check date parsing
SELECT
  date_string,
  toDateOrNull(date_string) as parsed_date,
  CASE
    WHEN toDateOrNull(date_string) IS NULL THEN 'Invalid date'
    ELSE 'Valid date'
  END as status
FROM events
LIMIT 10
```

## Best practices

1. **Use toTypeName() frequently** - Check types during development
2. **Sample data** - Always check sample data with types
3. **Validate assumptions** - Don't assume types, verify them
4. **Document types** - Keep track of expected vs actual types
5. **Test conversions** - Test type conversions with sample data

## Related documentation

- [Data types](/sql-reference/data-types)
- [Type conversion functions](/sql-reference/functions/type-conversion-functions)
