Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequel selecting too many columns

Tags:

ruby

sequel

It seems like the default select for Sequel is "select *", which causes all kinds of problems when you add some joins. At the very least you end up with the wrong ids in your objects (because there will then be more than one "id" column returned). Doing something like

.select("people.*")

would seem to work, but that treats the string passed in as a column and quotes it. So far I've had to revert back to bare SQL to solve this, but I know there has to be a better way.

like image 529
Phil Kulak Avatar asked Aug 03 '09 03:08

Phil Kulak


People also ask

Can you have too many columns SQL?

A common problem with SQL is the high probability of having too many columns in the projection. This may be due to reckless usage of SELECT * or some refactoring which removes the need to select some of the projected columns, but the query was not adapted.

How many columns is too many for a DB table?

The design of the table depends on the entity it needs to store. If all the data belongs together, then 50 columns (or even 100) might be the correct thing to do. So long as the table is normalized, there is no rule of thumb regarding size, apart from database capabilities and the need to optimize.

How many columns can SQL handle?

For the columns in a table, there is a maximum limit of 1024 columns in a table. SQL Server does have a wide-table feature that allows a table to have up to 30,000 columns instead of 1024.


1 Answers

The default behavior for Sequel is to select all columns, but it is easy to override. If you want to select only all columns from a single table:

.select(:people.*)

If you want to use a literal SQL string:

.select('people.*'.lit)

like image 191
Jeremy Evans Avatar answered Sep 20 '22 11:09

Jeremy Evans