Diesel: Column limits?

Created on 22 Jun 2016  路  7Comments  路  Source: diesel-rs/diesel

Are there column limits for tables used with diesel? For example if I use the code in diesel demo and add thirteen more fields:

CREATE TABLE posts (
  id SERIAL PRIMARY KEY,
  title VARCHAR NOT NULL,
  body TEXT NOT NULL,
  published BOOLEAN NOT NULL DEFAULT 'f',
  one integer,
  two integer,
  three integer,
  four integer,
  five integer,
  six integer,
  seven varchar,
  eight varchar,
  nine varchar,
  ten varchar,
  eleven varchar,
  twelve varchar,
  thirteen varchar
)

I get a trait bound error after running diesel migration redo:

<diesel macros>:18:64: 18:71 error: the trait bound `(schema::posts::columns::id, schema::posts::columns::title, schema::posts::columns::body, schema::posts::columns::published, schema::posts::columns::one, schema::posts::columns::two, schema::posts::columns::three, schema::posts::columns::four, schema::posts::columns::five, schema::posts::columns::six, schema::posts::columns::seven, schema::posts::columns::eight, schema::posts::columns::nine, schema::posts::columns::ten, schema::posts::columns::eleven, schema::posts::columns::twelve, schema::posts::columns::thirteen): diesel::SelectableExpression<schema::posts::table, (diesel::types::Integer, diesel::types::VarChar, diesel::types::Text, diesel::types::Bool, diesel::types::Nullable<diesel::types::Integer>, diesel::types::Nullable<diesel::types::Integer>, diesel::types::Nullable<diesel::types::Integer>, diesel::types::Nullable<diesel::types::Integer>, diesel::types::Nullable<diesel::types::Integer>, diesel::types::Nullable<diesel::types::Integer>, diesel::types::Nullable<diesel::types::VarChar>, diesel::types::Nullable<diesel::types::VarChar>, diesel::types::Nullable<diesel::types::VarChar>, diesel::types::Nullable<diesel::types::VarChar>, diesel::types::Nullable<diesel::types::VarChar>, diesel::types::Nullable<diesel::types::VarChar>, diesel::types::Nullable<diesel::types::VarChar>)>` is not satisfied [E0277]
<diesel macros>:18 :: FromClause { Identifier ( stringify ! ( $ name ) ) } } impl AsQuery for
                                                                                  ^~~~~~~
<diesel macros>:5:1: 5:71 note: in this expansion of table_body! (defined in <diesel macros>)
src/schema.rs:1:1: 1:40 note: in this expansion of table! (defined in <diesel macros>)
src/schema.rs:1:1: 1:40 note: in this expansion of infer_schema! (defined in src/lib.rs)
src/lib.rs:9:1: 9:23 note: in this expansion of include!
<diesel macros>:18:64: 18:71 help: run `rustc --explain E0277` to see a detailed explanation
<diesel macros>:18:64: 18:71 note: required because of the requirements on the impl of `diesel::query_builder::Query` for `diesel::query_builder::SelectStatement<(diesel::types::Integer, diesel::types::VarChar, diesel::types::Text, diesel::types::Bool, diesel::types::Nullable<diesel::types::Integer>, diesel::types::Nullable<diesel::types::Integer>, diesel::types::Nullable<diesel::types::Integer>, diesel::types::Nullable<diesel::types::Integer>, diesel::types::Nullable<diesel::types::Integer>, diesel::types::Nullable<diesel::types::Integer>, diesel::types::Nullable<diesel::types::VarChar>, diesel::types::Nullable<diesel::types::VarChar>, diesel::types::Nullable<diesel::types::VarChar>, diesel::types::Nullable<diesel::types::VarChar>, diesel::types::Nullable<diesel::types::VarChar>, diesel::types::Nullable<diesel::types::VarChar>, diesel::types::Nullable<diesel::types::VarChar>), (schema::posts::columns::id, schema::posts::columns::title, schema::posts::columns::body, schema::posts::columns::published, schema::posts::columns::one, schema::posts::columns::two, schema::posts::columns::three, schema::posts::columns::four, schema::posts::columns::five, schema::posts::columns::six, schema::posts::columns::seven, schema::posts::columns::eight, schema::posts::columns::nine, schema::posts::columns::ten, schema::posts::columns::eleven, schema::posts::columns::twelve, schema::posts::columns::thirteen), schema::posts::table>`

If I remove the thirteen column that error disappears.

All 7 comments

We may be able to add an on_unimplemented annotation for better errors in these cases (on nightly), but it seems like there are some problems with blanket impls (which funnily enough Sean found while building diesel): https://github.com/rust-lang/rust/issues/29628

One question, suppose I have a table with hundreds of fields (I know, I know -- I'm a journalist and we get crazy data) is there anything I can do?

@thejefflarson Well, that depends on how much time and effort you want to put into this :) Here are some options:

  1. Normalize that database so it uses a more sane schema :) _Edit:_ You can also use Views for that, of course.
  2. Submit a PR to diesel to add a "really-huge-tables" feature, where you repeat this stuff for far longer.
  3. Improve Rust itself to have more generic tuple support

@killercup Ha ok. 1 is sometimes not possible (I'm side-eying the census here, though I almost always don't need the whole thing).

I might take you up on 2 -- though even for me I can only think of a handful of datasets that may need more than 52 fields. I think I can do it if I need it, thanks for the pointer! And thanks for taking the time!

Option 4: Fix the linear growth in compile time that is linked to number of trait implementations in Rust itself and then I can implement this to be as large as people ask and turned on by default. (Easy, right? :trollface:)

For the record, I will accept a really-huge-tables feature.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattico picture mattico  路  4Comments

orionz picture orionz  路  3Comments

Fuckoffee picture Fuckoffee  路  3Comments

killercup picture killercup  路  3Comments

kanekv picture kanekv  路  3Comments