"Keith Medcalf" <kmedc...@dessus.com> writes: > Alternatively, to implement your original question, write an aggregate > function which returns the first non-null value it comes across, and use the > negated unix timestamp as an explicit rowid, depending on the fact that a > table-scan does an in-order traversal of the table btree:
Except for the names, the below code is *exactly*, character by character, as what I first wrote, but then I realised that the order of the values going to the step function might not be defined. So can I trust that I will get the order of my unix time primary key? It would be convenient if I can omit the timestamp argument in the function. > > typedef struct fnnCtx fnnCtx; > struct fnnCtx > { > double fnn; > int flag; > }; > > SQLITE_PRIVATE void fnnStep(sqlite3_context *context, int argc, sqlite3_value > **argv) > { > fnnCtx* p = sqlite3_aggregate_context(context, sizeof(fnnCtx)); > if (p && sqlite3_value_numeric_type(argv[0]) != SQLITE_NULL && p->flag == > 0) > { > p->fnn = sqlite3_value_double(argv[0]); > p->flag = 1; > } > } > > SQLITE_PRIVATE void fnnFinal(sqlite3_context *context) > { > fnnCtx* p = sqlite3_aggregate_context(context, 0); > if (p && p->flag == 1) > sqlite3_result_double(context, p->fnn); > } -- Steinar Midtskogen _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users