tursodatabase/turso

UUID type Runtime Error: cannot store BLOB value in TEXT column

Open

#6,221 创建于 2026年3月31日

在 GitHub 查看
 (2 评论) (1 反应) (0 负责人)Rust (1,001 fork)github user discovery
help wantedstrict tables

仓库指标

Star
 (19,103 star)
PR 合并指标
 (PR 指标待抓取)

描述

The docs provide two distinct ways of using uuid in tables for a PK.

The first is to have a STRICT table with uuid defined as the column type (what I would ideally love to have): https://docs.turso.tech/sql-reference/data-types

CREATE TABLE events (
    id uuid PRIMARY KEY,
    name varchar(100),
    event_date date,
    is_active boolean DEFAULT 1,
    metadata json
) STRICT;

INSERT INTO events VALUES (
    uuid4(),
    'Product Launch',
    '2025-03-15',
    1,
    '{"venue": "online"}'
);

This example does not work as of version 0.5.1. I get the following error: Error: Runtime error: cannot store BLOB value in TEXT column events.id (19) The docs also don't state how I would reference this ID as a FK in another table. Would it be BLOB, TEXT or UUID?

In the second example in the docs, the table is STRICT and the id PK is typed as BLOB. https://docs.turso.tech/sql-reference/extensions#examples

-- Generate UUIDs
SELECT uuid4_str();
-- '550e8400-e29b-41d4-a716-446655440000'

SELECT uuid_str(uuid4());
-- 'f47ac10b-58cc-4372-a567-0e02b2c3d479'

-- UUID v7 is time-ordered (good for primary keys)
SELECT uuid_str(uuid7());
-- '0190a5c0-1234-7abc-8def-0123456789ab'

-- Extract timestamp from UUID v7
SELECT uuid7_timestamp_ms(uuid7());
-- 1720000000000

-- Use in a table
CREATE TABLE documents (
    id BLOB PRIMARY KEY DEFAULT (uuid7()),
    title TEXT
);
INSERT INTO documents (title) VALUES ('My Document');
SELECT uuid_str(id), title FROM documents;

This example does work, but there is the issue of invalid UUID's being entered. I made a small example below:

turso> CREATE TABLE documents (
    id BLOB PRIMARY KEY DEFAULT (uuid7()),
    title TEXT
);
INSERT INTO documents (title) VALUES ('My Document');
SELECT uuid_str(id), title FROM documents;
┌──────────────────────────────────────┬─────────────┐
│ uuid_str (documents.id)              │ title       │
├──────────────────────────────────────┼─────────────┤
│ 019d4527-256f-7650-b709-469cd39da3f3 │ My Document │
└──────────────────────────────────────┴─────────────┘
turso> INSERT INTO documents VALUES ('not a uuid', 'My Document');

turso> SELECT uuid_str(id), title FROM documents;

┌──────────────────────────────────────┬─────────────┐
│ uuid_str (documents.id)              │ title       │
├──────────────────────────────────────┼─────────────┤
│ 019d4527-256f-7650-b709-469cd39da3f3 │ My Document │
├──────────────────────────────────────┼─────────────┤
│                                      │ My Document │
└──────────────────────────────────────┴─────────────┘
turso>

贡献者指南