Skip to main content

resolve_multi_table_columns

Function resolve_multi_table_columns 

Source
pub fn resolve_multi_table_columns(
    cols_part: &str,
    sql: &str,
    schema_tables: &[TableDef],
    source_file: &str,
) -> Result<Vec<ColumnDef>>
Expand description

Resolve a SELECT column list against a multi-table JOIN context. Shared across dialect parsers (postgres, mysql, sqlite): they detect the JOIN via has_outer_join, pull the columns-part out of the SELECT, and call this function to build the typed ColumnDef list.

Rejects SELECT * across joins with a v1.2 pointer — listing qualified columns explicitly is required.

Also rejects unaliased name collisions across joined tables. If two selected columns share the same effective name (e.g. users.id and orgs.id) without an explicit AS alias, the generated row type would have duplicate fields and the underlying driver (sqlx derive, Go db tag, etc) couldn’t scan them correctly. Users must write SELECT users.id AS user_id, orgs.id AS org_id ..., matching sqlc’s convention.