Skip to content

TableIterator doesn't like single-column tuples #1031

@ccleve

Description

@ccleve
#[pg_extern]
fn single_column() -> TableIterator<'static, (name!(foo_col, String) /* name!(bar_col, String) */,)>
{
    let mut out = vec![];
    let foo = "foo".to_owned();
    let bar = "bar".to_owned();
    out.push((foo /*bar*/,));
    TableIterator::new(out.into_iter())
}

# select * from single_column();
ERROR:  return type must be a row type

Uncomment the reference to bar in two places and it works fine.

The workaround is to use SetOfIterator for single-column tables.

Rust also has a weird syntax issue that tripped me up for an hour. TableIterator needs a tuple type, but if you do something like this: out.push((foo)), the parentheses get ignored. You need the trailing comma: out.push((foo,)). This is a Rust thing, not a pgx thing, but a bit of documentation on it in https://github.com/tcdi/pgx/blob/master/pgx-examples/srf/src/lib.rs might save others some time.

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