pg_tiktoken
pg_tiktoken copied to clipboard
Mark tiktoken functions as IMMUTABLE by default
Description
When using tiktoken_count in a generated column on managed Postgres instances (like Neon), we encounter:
ERROR: generation expression is not immutable
Since tokenization is deterministic (same input → same output), marking these functions as IMMUTABLE in the extension itself would allow direct use in generated columns without requiring superuser privileges.
Example Use Case
CREATE TABLE documents (
content text NOT NULL,
token_count integer GENERATED ALWAYS AS (tiktoken_count('cl100k_base', content)) STORED
);
Benefits
- Works out of the box on managed Postgres instances
- Enables use in generated columns
- Follows Postgres best practices for deterministic functions
Sorry, missed that issue. Makes a lot of sense.