liveBook · Manning

Varchar data type

As explained in DuckDB in Action

The VARCHAR data type represents variable-length character strings.

VARCHAR represents variable-length character strings. In data workflows, it provides a safe landing type when source values are inconsistent or automatic type detection cannot classify them reliably. section 5.6 section 5.2.1

Use VARCHAR when:

  • Importing SQLite columns whose observed values conflict with declared types. section 5.6
  • Preserving CSV values that cannot be cast to BOOLEAN, BIGINT, DOUBLE, TIME, DATE, or TIMESTAMP. section 5.2.1
  • Delaying interpretation until values can be explicitly cast to their intended types. section 5.6

Normalize an imported SQLite view

Set sqlite_all_varchar to true, then redefine the Player view from sqlite_scan. Keep source values as VARCHAR and explicitly cast identifiers to BIGINT, birthday to DATE, and measurements to FLOAT. Querying the revised view returns usable int64, date, and float columns. section 5.6

USE main;
CREATE OR REPLACE VIEW Player AS
FROM sqlite_scan('database.sqlite', 'Player')
SELECT * REPLACE (
  id :: BIGINT AS id,
  player_api_id :: BIGINT AS player_api_id,
  player_fifa_api_id :: BIGINT AS player_fifa_api_id,
  birthday :: DATE AS birthday,
  height :: FLOAT AS height,
  weight :: FLOAT AS weight
);

Inspect the complete CREATE OR REPLACE VIEW statement for the VARCHAR-first import and explicit recasting workflow. section 5.6

How DuckDB in Action covers it

How deep it goes
Explains VARCHAR as a fallback and demonstrates explicit recasting, but does not discuss storage or execution internals.
Examples
Demonstrates mismatched SQLite player fields, CSV inference, and a recast Player view.
What you can do after
Operate/configure DuckDB imports by staging values as VARCHAR and casting columns into usable types.
How it connects
Connects VARCHAR with SQLite, DuckDB, CSV parsing, automatic type detection, and explicit casting.

Also explained in

Compare how 4 books explain varchar data type →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of DuckDB in Action. The section links point to the parts of the book it draws on.