Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow reading composite values into a Row-like struct #366

Open
@kostrowski

Description

@kostrowski

It would be useful to be able to treat the value of a composite-value column as aRow. Presently, to read composite values you need to usepostgres-derive or handle the raw bytes returned byRow::get_bytes(...). In certain situations neither option is attractive. Usingpostgres-derive requires one to define a struct matching the fields of the composite value and results in parsing based on name matching, which could be a performance issue. Manually handling the raw bytes returned byRow::get_bytes(...) could avoid the performance issue, but that would mean duplicating a fair amount of code that is already inpostgres-protocol in the form ofmessage::DataRowBodyandmessage::DataRowRanges.

I'm not entirely certain of the best approach within the library (a simple hack is to makeDataRowBody andDataRowRanges externally constructible and feed the field's raw bytes into them).

An example use case would be in working with class-table inheritance, where you might want to query the concrete type variants as composites:

let sql ="\    SELECT widget.type, widget.name, machine, toy\    FROM widget LEFT JOIN machine USING (id) LEFT JOIN toy USING (id)\";for rowin&conn.query(sql,&[]).unwrap(){let ty = str::from_utf8(row.get_bytes(0).unwrap()).unwrap();let name = row.get(1);let kind =match ty{"machine" =>{let row:Composite = row.get(2);WidgetKind::Machine{gears: row.get(0),operator: row.get(1),}},"toy" =>{let row:Composite = row.get(3);WidgetKind::Toy{minimum_age: row.get(0),}},};let widget =Widget{ name, kind};println!("{:?}", widget);}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp