Diesel: Bug at using tables with more than 16 fields

Created on 13 Oct 2016  路  13Comments  路  Source: diesel-rs/diesel

There is a little bug when you have a table with more than 16 fields.
To check it, I use this table:

CREATE TABLE foo (
    id INT PRIMARY KEY,

    foo01 TEXT,
    foo02 TEXT,
    foo03 TEXT,
    foo04 TEXT,
    foo05 TEXT,
    foo06 TEXT,
    foo07 TEXT,
    foo08 TEXT,
    foo09 TEXT,
    foo10 TEXT,
    foo11 TEXT,
    foo12 TEXT,
    foo13 TEXT,
    foo14 TEXT,
    --foo15 TEXT,
    foo16 TEXT
);
#[derive(Queryable)]
pub struct Foo {
    pub id: i32,

    pub foo01: String,
    pub foo02: String,
    pub foo03: String,
    pub foo04: String,
    pub foo05: String,
    pub foo06: String,
    pub foo07: String,
    pub foo08: String,
    pub foo09: String,
    pub foo10: String,
    pub foo11: String,
    pub foo12: String,
    pub foo13: String,
    pub foo14: String,
    //pub foo15: String,
    pub foo16: String,
}

And I run the next command

$ dropdb diesel_demo && diesel setup && cargo test

It should be ok. Now, comment out the field 'foo15' and try it again.

Most helpful comment

@lancecarlson I understand your frustration, but sadly it's a known limitation right now. In Diesel, but also in Rust itself: Tables are represented as tuples and currently, Rust does not have a way to deal with arbitrarily large tuples.

If you want to know more, have a look at Diesel PR #747, the resulting https://github.com/rust-lang/rfcs/pull/1921 and the newer https://github.com/rust-lang/rfcs/pull/1935.

All 13 comments

What error are you getting? I think you are running into the default column number limitation. The docs for table! (which is also used internally) say:

By default this allows a maximum of 16 columns per table, in order to reduce compilation time. You can increase this limit to 26 by enabling the large-tables feature, or up to 52 by enabling the huge-tables feature. Enabling huge-tables will substantially increase compile times.

Does this work for you when enabling the large-tables feature for Diesel in your Cargo.toml?

I'm supposed that is the problem.

What there is to write in Cargo.toml to enable it? I could not find in doc.

What there is to write in Cargo.toml to enable it?

Where you define diesel as a dependency, you can also list the features you want to enable, like so:

[dependencies]
diesel = { version = "0.8", features = ["postgres", "large-tables"] }

The error that I get is like

error[E0277]: the trait bound `(...)>` is not satisfied

I had in Cargo.toml:

diesel = "^0.8"
diesel_codegen = { version = "^0.8", features = ["postgres"] }

It works now using:

diesel = { version = "^0.8", features = ["large-tables"] }
diesel_codegen = { version = "^0.8", features = ["postgres"] }

Thanks!

Great!

I just ran into this issue and this is ridiculous. Why is there such a thing as "large table support?" Shouldn't it default to any size table you like?

@lancecarlson I understand your frustration, but sadly it's a known limitation right now. In Diesel, but also in Rust itself: Tables are represented as tuples and currently, Rust does not have a way to deal with arbitrarily large tuples.

If you want to know more, have a look at Diesel PR #747, the resulting https://github.com/rust-lang/rfcs/pull/1921 and the newer https://github.com/rust-lang/rfcs/pull/1935.

Actually I guess this answers my other question

The error for this is so ambiguous it's kind of ridiculous. Hopefully rust improves, removes this limitation for enums, and people stop using huge macros as fundamental functionality in their libraries.

for anybody reading in 2019 large-tables got renamed to 32-column-tables for some reason:

diesel = { version = "1.0.0", features = ["sqlite","mysql","32-column-tables"] }

I guess to avoid confusion with "large amounts of records tables"?

anyway, this is the error that got me here:

warning: use of deprecated item 'diesel::expression::ops::Mul::<Lhs, Rhs>::new': The large-tables feature has been renamed to 32-column-tables

in case anybody has the same problem.

Yes, they were renamed when we were at the point of otherwise adding extra-extra-huge-tables as a feature name. 32-column-tables has also been the default for nearly 2 years now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mkroman picture mkroman  路  3Comments

Fuckoffee picture Fuckoffee  路  3Comments

ivan picture ivan  路  4Comments

jimmycuadra picture jimmycuadra  路  3Comments

ghost picture ghost  路  3Comments