pub struct ColumnIdentifier { /* private fields */ }Expand description
A SQL column identifier with proper case handling per SQL:1999.
This type handles column references with optional table and schema qualifiers. Each component (schema, table, column) has independent quoted/unquoted semantics.
§Supported Forms
| SQL Form | Description |
|---|---|
id | Unqualified column reference |
users.id | Table-qualified column reference |
myschema.users.id | Fully-qualified column reference |
§SQL:1999 Compliance
Per SQL:1999, identifier handling depends on whether each component was quoted:
| Input | Quoted | Canonical | Matches mycolumn? |
|---|---|---|---|
MyColumn | No | mycolumn | Yes |
"MyColumn" | Yes | MyColumn | No |
MYCOLUMN | No | mycolumn | Yes |
§Example
use vibesql_ast::ColumnIdentifier;
// Unquoted identifiers are case-insensitive
let c1 = ColumnIdentifier::simple("MyColumn", false);
let c2 = ColumnIdentifier::simple("mycolumn", false);
assert_eq!(c1, c2);
// Quoted identifiers are case-sensitive
let quoted = ColumnIdentifier::simple("MyColumn", true);
assert_ne!(c1, quoted);
// Table-qualified column
let qualified = ColumnIdentifier::qualified("users", false, "id", false);
assert_eq!(qualified.canonical(), "users.id");Implementations§
Source§impl ColumnIdentifier
impl ColumnIdentifier
Sourcepub fn simple(column: &str, quoted: bool) -> Self
pub fn simple(column: &str, quoted: bool) -> Self
Create a simple (unqualified) column identifier.
§Arguments
column- The column name as written by the userquoted- Whether the identifier was quoted (delimited) in SQL
§Example
use vibesql_ast::ColumnIdentifier;
let c = ColumnIdentifier::simple("MyColumn", false);
assert_eq!(c.canonical(), "mycolumn");
assert_eq!(c.display(), "MyColumn");Sourcepub fn qualified(
table: &str,
table_quoted: bool,
column: &str,
column_quoted: bool,
) -> Self
pub fn qualified( table: &str, table_quoted: bool, column: &str, column_quoted: bool, ) -> Self
Create a table-qualified column identifier.
§Arguments
table- The table name as written by the usertable_quoted- Whether the table was quoted in SQLcolumn- The column name as written by the usercolumn_quoted- Whether the column was quoted in SQL
§Example
use vibesql_ast::ColumnIdentifier;
let c = ColumnIdentifier::qualified("Users", false, "ID", false);
assert_eq!(c.canonical(), "users.id");
assert_eq!(c.table_canonical(), Some("users"));
assert_eq!(c.column_canonical(), "id");Sourcepub fn fully_qualified(
schema: &str,
schema_quoted: bool,
table: &str,
table_quoted: bool,
column: &str,
column_quoted: bool,
) -> Self
pub fn fully_qualified( schema: &str, schema_quoted: bool, table: &str, table_quoted: bool, column: &str, column_quoted: bool, ) -> Self
Create a fully-qualified (schema.table.column) identifier.
§Arguments
schema- The schema name as written by the userschema_quoted- Whether the schema was quoted in SQLtable- The table name as written by the usertable_quoted- Whether the table was quoted in SQLcolumn- The column name as written by the usercolumn_quoted- Whether the column was quoted in SQL
§Example
use vibesql_ast::ColumnIdentifier;
let c = ColumnIdentifier::fully_qualified(
"myApp", true, // quoted schema
"users", false, // unquoted table
"ID", false // unquoted column
);
assert_eq!(c.canonical(), "myApp.users.id");Sourcepub fn unquoted(column: &str) -> Self
pub fn unquoted(column: &str) -> Self
Create an unquoted column identifier (convenience constructor).
This creates a simple, case-insensitive column reference.
§Example
use vibesql_ast::ColumnIdentifier;
let c = ColumnIdentifier::unquoted("MyColumn");
assert_eq!(c.canonical(), "mycolumn");Sourcepub fn quoted(column: &str) -> Self
pub fn quoted(column: &str) -> Self
Create a quoted column identifier (convenience constructor).
This creates a simple, case-sensitive column reference.
§Example
use vibesql_ast::ColumnIdentifier;
let c = ColumnIdentifier::quoted("MyColumn");
assert_eq!(c.canonical(), "MyColumn");Sourcepub fn table_column(table: &str, column: &str) -> Self
pub fn table_column(table: &str, column: &str) -> Self
Create a table.column reference with unquoted identifiers.
§Example
use vibesql_ast::ColumnIdentifier;
let c = ColumnIdentifier::table_column("users", "id");
assert_eq!(c.canonical(), "users.id");Sourcepub fn from_canonical(canonical: String, quoted: bool) -> Self
pub fn from_canonical(canonical: String, quoted: bool) -> Self
Create an identifier from a canonical name (for internal use).
This is used when loading from persistence where we only have the canonical form. The display form is set to match canonical.
Sourcepub fn canonical(&self) -> &str
pub fn canonical(&self) -> &str
Get the canonical form of the identifier.
This is used for HashMap keys and equality comparison. Format: “schema.table.column” or “table.column” or “column”
Sourcepub fn display(&self) -> &str
pub fn display(&self) -> &str
Get the display form of the identifier.
This preserves the user’s original input and should be used in error messages and user-facing output.
Sourcepub fn column_canonical(&self) -> &str
pub fn column_canonical(&self) -> &str
Get the column name in canonical form.
Sourcepub fn column_display(&self) -> &str
pub fn column_display(&self) -> &str
Get the column name in display form.
Sourcepub fn is_column_quoted(&self) -> bool
pub fn is_column_quoted(&self) -> bool
Check if the column was quoted.
Sourcepub fn table_canonical(&self) -> Option<&str>
pub fn table_canonical(&self) -> Option<&str>
Get the table name in canonical form (if qualified).
Sourcepub fn table_display(&self) -> Option<&str>
pub fn table_display(&self) -> Option<&str>
Get the table name in display form (if qualified).
Sourcepub fn is_table_quoted(&self) -> bool
pub fn is_table_quoted(&self) -> bool
Check if the table was quoted (if qualified).
Sourcepub fn schema_canonical(&self) -> Option<&str>
pub fn schema_canonical(&self) -> Option<&str>
Get the schema name in canonical form (if fully qualified).
Sourcepub fn schema_display(&self) -> Option<&str>
pub fn schema_display(&self) -> Option<&str>
Get the schema name in display form (if fully qualified).
Sourcepub fn is_schema_quoted(&self) -> bool
pub fn is_schema_quoted(&self) -> bool
Check if the schema was quoted (if fully qualified).
Sourcepub fn is_qualified(&self) -> bool
pub fn is_qualified(&self) -> bool
Check if this is a table-qualified column (has table but not schema).
Sourcepub fn is_fully_qualified(&self) -> bool
pub fn is_fully_qualified(&self) -> bool
Check if this is a fully-qualified column (has schema.table.column).
Sourcepub fn is_ambiguous(&self) -> bool
pub fn is_ambiguous(&self) -> bool
Check if this column reference is ambiguous (no table qualifier).
Sourcepub fn into_canonical(self) -> String
pub fn into_canonical(self) -> String
Get the canonical form as an owned String.
Sourcepub fn matches_column_name(&self, name: &str, case_sensitive: bool) -> bool
pub fn matches_column_name(&self, name: &str, case_sensitive: bool) -> bool
Check if this column matches another by canonical column name only.
This ignores table and schema qualifiers, useful for finding columns by name across different tables.
Sourcepub fn resolve_against(&self, table: &TableIdentifier) -> Self
pub fn resolve_against(&self, table: &TableIdentifier) -> Self
Resolve an ambiguous column against a table.
If this column is unqualified, creates a new column identifier qualified with the given table. If already qualified, returns self.
Sourcepub fn matches(&self, other: &ColumnIdentifier) -> bool
pub fn matches(&self, other: &ColumnIdentifier) -> bool
Check if this column reference matches another.
Matching rules:
- An unqualified column matches if the column names match
- A qualified column matches only if both table and column match
- A fully-qualified column matches only if schema, table, and column match
Sourcepub fn unqualify(&self) -> Self
pub fn unqualify(&self) -> Self
Create a column identifier by stripping qualifiers.
Returns a new unqualified column identifier with just the column name.
Sourcepub fn with_table(&self, table: &str, table_quoted: bool) -> Self
pub fn with_table(&self, table: &str, table_quoted: bool) -> Self
Create a column identifier with a different table qualifier.
Useful when remapping columns during query planning.
Trait Implementations§
Source§impl Clone for ColumnIdentifier
impl Clone for ColumnIdentifier
Source§fn clone(&self) -> ColumnIdentifier
fn clone(&self) -> ColumnIdentifier
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more