osquery / osquery/osquery

In patches table, the dates should be represented as dates, not strings

Open
#6,577 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug virtual tables
Dominant language
C++
Stars
23.6k
Forks
2.6k
Avg merge
6d 7h
Merged PRs (30d)
14

Description

Feature request

What new feature do you want?

When performing a query like select * from patches order by installed_on the query sorts the column on M/D/YYYY STRING instead of a date. When attempting to use SQL to have it sort as a date it turns out that the string format is representing dates wihout leading zeros, making it impossible to sort it like this:

SELECT csname, 
installed_on, substr(installed_on,7,4) || substr(installed_on,1,2) || substr(installed_on,4,2) AS sort_date 
FROM patches ORDER BY sort_date ASC

As the substrings are moving targets without leading zeros.

How is this new feature useful?

If you are trying to create a report of patch levels for windows hosts, none of the patch dates come in order, so you have to post process the data instead of being able to use it right from osquery, or kolide/fleet.

How can this be implemented?

I looked at this PR: https://github.com/osquery/osquery/pull/2837#issuecomment-668347723
and https://github.com/osquery/osquery/blob/master/specs/windows/patches.table

As I understand it, osquery uses a subset of sqlite for virtual tables, and sqlite doesn't have date datatypes. It seems to me if the installed_on string were formatted as YYYYMMDD that would be sortable in an asc or desc fashion, or if the column were EPOCH time based, that would be sortable as well.

Thank you.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with specs/windows/patches.table and the reported SELECT query to understand how installed_on is exposed. Compare the proposed sortable date representations against SQLite's documented date handling and the existing patches table behavior. Done means installed_on can be ordered chronologically in ascending and descending queries without post-processing.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, sql, sqlite
Domain
databases, operating-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.