python - Why does SQLite3 not yield an error -


i quite new sql, trying bugfix output of sql-query. question not concern bug, rather why sqlite3 not yield error when should.

i have query string looks like:

querystring = ("select e.event_id, "      "count(e.event_id), "     "e.state, "     "min(e.boot_time) boot_time, "     "e.time_occurred, "     "coalesce(e.info, 0) info "     "from events e "     "join leg on leg.id = e.leg_id "     "group e.event_id "     "order leg.num_leg desc, "     "e.event_id asc;\n"     ) 

this yields output no errors.

what dont understand, why there no error when group e.event_id , e.state , e.time_occurred not contain aggregate-functions , not part of group statement?

e.state string column. e.time_occurred integer column.

i using querystring in python.

sqlite , mysql allow bare columns in aggregation query. explained in documentation:

in query above, "a" column part of group clause , each row of output contains 1 of distinct values "a". "c" column contained within sum() aggregate function , output column sum of "c" values in rows have same value "a". result of bare column "b"? answer "b" result value "b" in 1 of input rows form aggregate. problem not know input row used compute "b", , in many cases value "b" undefined.

your particular query is:

select e.event_id, count(e.event_id), e.state, min(e.boot_time) boot_time,        e.time_occurred, coalesce(e.info, 0) info events e join      leg      on leg.id = e.leg_id " group e.event_id  order leg.num_leg desc, e.event_id asc; 

if e.event_id primary key in events, syntax supported ansi standard, because event_id sufficient uniquely define other columns in row in events.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -