Skip to main content

ColumnSchema

Struct ColumnSchema 

Source
pub struct ColumnSchema {
Show 23 fields pub name: String, pub ty: DataType, pub nullable: bool, pub default: Option<Value<'static>>, pub runtime_default: Option<String>, pub collation_name: Option<String>, pub auto_increment: bool, pub user_enum_type: Option<String>, pub user_domain_type: Option<String>, pub user_composite_type: Option<String>, pub acl: Vec<AclItem>, pub on_update_runtime: Option<String>, pub collation: Collation, pub is_unsigned: bool, pub inline_enum_variants: Option<Vec<String>>, pub inline_set_variants: Option<Vec<String>>, pub generated_stored_expr: Option<String>, pub identity_always: bool, pub default_text: Option<String>, pub auto_restart: Option<i64>, pub scalar_row_source: bool, pub mysql_int_width: Option<MysqlIntWidth>, pub mysql_fsp: Option<u8>,
}
Expand description

Each bool is an independent, separately-persisted column attribute (nullable, auto_increment, is_unsigned, identity_always) that the catalog appendix reads and writes by name. Packing them into a bitflags word would buy nothing and would put a decoding step between the on-disk format and every reader of the schema.

Fields§

§name: String§ty: DataType§nullable: bool§default: Option<Value<'static>>

Optional DEFAULT value, frozen at CREATE TABLE time. None means “no default” (so omitted columns become NULL, or error out when the column is NOT NULL). Literal defaults take this path.

v7.37.42-arena Phase 1: explicitly Value<'static> — catalog defaults must outlive any per-query arena.

§runtime_default: Option<String>

v7.9.21 — for DEFAULT expressions that need INSERT-time evaluation (e.g. DEFAULT now(), DEFAULT CURRENT_TIMESTAMP), the Display form of the expression. The engine re-parses it on each INSERT default-fill, evaluates against an empty row context, and coerces to the column type. mailrs G4. Persisted in catalog FILE_VERSION 15+; older catalogs deserialise with None.

§collation_name: Option<String>

MySQL-style AUTO_INCREMENT. When set, an INSERT that leaves this column unbound (or sets it to NULL) gets the next integer computed from the column’s current max + 1. v7.39 (round 676) — the collation NAME as written, when the column carried an explicit COLLATE.

spg_sql::Collation cannot carry it: it is a two-variant MySQL enum and from_collation_name folds C, POSIX, en_US and default all into Binary. Without the name pg_attribute.attcollation can only ever report the type’s default, which is what F36 records as “the declaration is taken and ignored”.

None means the column was written without a COLLATE clause and takes its type’s collation. Persisted through the v88 appendix, which costs two bytes for a table that declares none.

§auto_increment: bool§user_enum_type: Option<String>

v7.17.0 Phase 1.4 — when the column is bound to a user- defined ENUM type (the parser saw an unknown type ident and the engine resolved it against catalog.enum_types), this carries the enum name so INSERT/UPDATE can validate the cell value against the enum’s labels. ty is DataType::Text in that case. Persisted in catalog FILE_VERSION 29+; older catalogs deserialise with None.

§user_domain_type: Option<String>

v7.17.0 Phase 1.5 — when the column is bound to a user- defined DOMAIN (the parser saw an unknown type ident and the engine resolved it against catalog.domain_types), this carries the domain name. ty is the domain’s base type; INSERT/UPDATE re-evaluates the domain’s CHECK list

  • NOT NULL against the cell value. Persisted in catalog FILE_VERSION 30+; older catalogs deserialise with None.
§user_composite_type: Option<String>

v7.39 (read01 round 56) — when the column is bound to a user-defined COMPOSITE type. ty stays DataType::Jsonb (the on-disk form), but the engine REHYDRATES the stored JSON into a Value::Composite on read, so field access (p).x, = ROW(…), ordering and the canonical (2,b) text form all work — they were already implemented on Value::Composite; what was missing was that the column never recorded WHICH composite type it holds (this field’s doc comment existed for two releases, the field itself did not). Persisted in the composite-column appendix (FILE_VERSION 63+); older catalogs deserialise with None.

§acl: Vec<AclItem>

v7.39 (read01 round 59) — column-level privileges (PG pg_attribute.attacl). GRANT SELECT (pub) ON t TO dan lands here and does NOT touch the table’s relacl. Empty = no column grant, which is every column until one is made.

§on_update_runtime: Option<String>

v7.17.0 Phase 2.1 — MySQL ON UPDATE CURRENT_TIMESTAMP column attribute. When Some(expr_src), an UPDATE that does NOT bind this column overrides the new value with the engine-evaluated expression (always now() in v7.17.0). Stored as Display-form source so storage stays free of spg-sql; the engine re-parses at UPDATE time. Persisted in catalog FILE_VERSION 32+; older catalogs deserialise with None — preserves the existing “silent ignore” behaviour for snapshots written before the upgrade.

§collation: Collation

v7.17.0 Phase 2.5 — text collation. Pre-2.5 SPG accepted COLLATE <name> clauses but discarded the name, so a column declared COLLATE "case_insensitive" (or any MySQL _ci collation) still compared byte-wise — a Tier-S silent failure where WHERE name = 'foo' never matched stored 'Foo'. This carries the parser-derived classification so the engine’s WHERE evaluator can route text equality through a case-aware compare. Binary (the default) preserves the prior byte-wise behaviour. Only CaseInsensitive lands in the catalog appendix — Binary columns stay implicit, keeping snapshots compact. Persisted in catalog FILE_VERSION 34+; older catalogs deserialise every column as Binary.

§is_unsigned: bool

v7.17.0 Phase 4.4 — MySQL UNSIGNED modifier flag. Drives engine-side INSERT / UPDATE range enforcement (rejects negative values on UNSIGNED int columns). Pre-4.4 the parser consumed and discarded the keyword silently, so every UNSIGNED column quietly accepted negatives — a Tier-A correctness drift. Sparse: only UNSIGNED columns land in the catalog appendix; the default false keeps snapshots compact for the common signed-int path. Persisted in catalog FILE_VERSION 35+; older catalogs deserialise every column as is_unsigned = false.

§inline_enum_variants: Option<Vec<String>>

v7.17.0 Phase 3.P0-36 — MySQL inline ENUM('a','b','c') value list. Distinct from user_enum_type (which points to a separately CREATE TYPE’d PG enum); this carries the column-local list MySQL DDL declares inline. When Some, ty is DataType::Text and INSERT/UPDATE validates the cell value against this list. Variant ORDER is preserved (MySQL uses it for ORDER BY col). Sparse: only ENUM columns land in the catalog appendix. Persisted in catalog FILE_VERSION 41+; older catalogs deserialise with None — preserves silent-drop behaviour for snapshots written before P0-36.

§inline_set_variants: Option<Vec<String>>

v7.17.0 Phase 3.P0-37 — MySQL inline SET('a','b','c') variant list. Storage is TEXT (canonical comma-joined in definition order, de-duplicated). INSERT/UPDATE validates every comma-separated token against this list. Sparse: only SET columns land in the catalog appendix. Persisted in catalog FILE_VERSION 42+; older catalogs deserialise with None.

§generated_stored_expr: Option<String>

v7.37.7(sentori Epic 3 P1)— GENERATED ALWAYS AS (<expr>) STORED computed-column source. When Some, INSERT / UPDATE recompute the cell against the candidate row(re-parse the stored Display form and evaluate)and overwrite any user-supplied value, matching PG’s stored-generated-column semantics. None (the default) preserves the regular “column value is whatever the caller passed” path. Persisted in catalog FILE_VERSION 50+; older catalogs deserialise with None.

§identity_always: bool

v7.38 (read01) — GENERATED ALWAYS AS IDENTITY. Both identity flavours set auto_increment; this additionally marks the ALWAYS flavour, whose explicit INSERT value PG rejects (“cannot insert a non-DEFAULT value into column …”) unless OVERRIDING SYSTEM VALUE. false (serial / BY DEFAULT) keeps the permissive path. In-memory only for now — not yet in the catalog appendix, so a reloaded table deserialises as false (the pre-existing permissive behaviour).

§default_text: Option<String>

v7.38 (read01) — the DEFAULT expression’s source text, deparsed to PG-compatible form at CREATE TABLE time (e.g. 0, (3 + 4), 'hi'::text, now(), CURRENT_DATE). Distinct from default (the coerced value the INSERT path fills) and runtime_default (the recompute-per-row Display form): those lose the source spelling, so information_schema.columns.column_default / pg_attrdef / pg_get_expr reported the coerced render (0.00 for numeric(10,2) DEFAULT 0) instead of PG’s 0. None for a column with no explicit default. Persisted in catalog FILE_VERSION 58+; older catalogs deserialise with None.

§auto_restart: Option<i64>

v7.39 (round 220) — ALTER TABLE … ALTER COLUMN … RESTART [WITH n] on an identity column. SPG’s identity allocation is a max+1 scan; this floor lifts the next allocated value to at least n (max(max+1, n)) — exactly what a dump-restore RESTART needs, and safer than PG for a backward RESTART (no duplicate-key landmine). Persisted in the FILE_VERSION 73+ sparse appendix; older catalogs deserialise with None.

§scalar_row_source: bool

v7.39 (read01 round 78) — this column is the ONLY column of a FROM item that calls a function returning a BASE type, so the item’s row type IS this column: a whole-row reference collapses to the value (SELECT j FROM jsonb_array_elements('[1]') AS j1, PG). Runtime only — a catalogued table column is never one, and it is not persisted.

§mysql_int_width: Option<MysqlIntWidth>

v7.39 (round 386, type-fidelity epic P1) — the declared MySQL narrow integer width (TINYINT / MEDIUMINT) whose range the storage ty (SmallInt / Int) is too wide to enforce. None for every other column. Drives the epic-P2 write-path range check. Persisted in the FILE_VERSION 81+ sparse appendix; older catalogs deserialise as None.

§mysql_fsp: Option<u8>

v7.39 (round 424, type-fidelity epic) — the declared MySQL fractional-seconds precision of a temporal column: DATETIME(3) is Some(3), a BARE DATETIME / TIME / TIMESTAMP is Some(0) (MySQL’s default is zero — the fraction is dropped on write), and None means “not a MySQL-declared temporal column”, which is every PG column and leaves microsecond behaviour untouched.

Drives write-path truncation (toward zero) and render padding (exactly this many digits, .000 when the fraction is zero). Persisted in the FILE_VERSION 82+ sparse appendix; older catalogs deserialise as None.

Implementations§

Source§

impl ColumnSchema

Source

pub fn new( name: impl Into<String>, ty: DataType, nullable: bool, ) -> ColumnSchema

Source

pub fn with_default(self, default: Value<'static>) -> ColumnSchema

Builder-style helper to attach a default value to an otherwise plain column schema. Used by the engine when CREATE TABLE specifies column TYPE DEFAULT <expr>.

Source

pub fn with_runtime_default(self, expr: impl Into<String>) -> ColumnSchema

v7.9.21 — builder for runtime-evaluated defaults (DEFAULT now(), DEFAULT CURRENT_TIMESTAMP, …). expr is the Expr’s Display form, re-parsed by the engine at each INSERT.

Source

pub const fn with_auto_increment(self) -> ColumnSchema

Builder-style helper to mark a column as AUTO_INCREMENT.

Trait Implementations§

Source§

impl Clone for ColumnSchema

Source§

fn clone(&self) -> ColumnSchema

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ColumnSchema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ColumnSchema

Source§

fn eq(&self, other: &ColumnSchema) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ColumnSchema

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.