stephenafamo/bob

Missing columns and values with GetColumnValues

hiendv opened this issue · 1 comments

I was looking at GetColumnValues and noticed that we only take the first object to compute columns. This leaves out values from richer object. There is also a test for the issue but why is this an expected behavior? Thank you.

testGetColumnValues(t, "first has fewer columns", testGetColumnsCase[SettableUser]{
	Rows:    []SettableUser{user3, user4},
	Columns: []string{"id", "first_name", "last_name"},
	Values: [][]bob.Expression{
		{expr.Arg(3), expr.Arg("John"), expr.Arg("Doe")},
		{expr.Arg(4), expr.Arg("Jane"), expr.Arg("Does")},
	},
})
// bio column is left out which makes the InsertMany failed because of missing data.

This is done this way for 2 reasons:

  1. For efficiency. Having to check all the values in all the passed objects would make a bulk insert far less efficient.
  2. If we imagine a query of the form
    INSERT INTO 
    table (col1, col2, col3) VALUES 
    (val11, val12, val13), 
    (val21, val22, val23)
    It would be generally expected that they all have the same number of set columns.