Learned this from a friend. The types are null, integer, real, text, and blob. My friend describes them thusly:

  • Null stores nothing, but like, actively nothing, as opposed to the absence of a thing.
  • Integer is a signed integer, up to 8 bytes.
  • Real is always an 8-byte float.
  • Text is an arbitrary-length UTF-8 or UTF-16.
  • Blob is an arbitrary-length anything-else. But I hope you remembered what you put there. Because it sure isn’t gonna tell you. Oh, and it doesn’t have strong typing, so if you ask for it back as an integer, it’ll quite happily give you it back as an integer, especially if that doesn’t make sense!
  • fiah@discuss.tchncs.de
    link
    fedilink
    arrow-up
    2
    ·
    1 year ago

    why not? assuming you’re saving them all in UTC they should be perfectly sortable and comparable (before, equal, after) as strings, even with varying amounts of precision when you compare substrings. You can’t really do math with them of course, but that’s what I meant about how DBs interpret dates and time: if you use it do to math and then you also use your application’s date library to do math, you’ll likely run into situations where the two come to different answers due to timezone settings, environments, DB drivers and the like. Of course if I could rely on the DB to do the math exactly the way I’d expect it to, then having that ability is awesome, however that requires more knowledge about databases and their environments than I currently have

    • ramirezmike@programming.dev
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      obviously it depends on your requirements but what I meant was you can’t compare them at the DB level within queries… you have to pull the data out into your application layer to use your date library.

      The problem there is you effectively need to grab more data than you need to answer queries like “which record has the most recent date” or “give me all the records between the values of the result of this subquery”. it can quickly become a massive bottleneck and may even prevent you from doing certain types of queries at all due to memory limitations.

      • fiah@discuss.tchncs.de
        link
        fedilink
        arrow-up
        3
        ·
        edit-2
        1 year ago

        But, you totally can? When you store all your dates as an ISO 8601 string (UTC, so with Z at the end), you can simply compare the strings themselves with no further complications, if the strings match, the dates match, if one string is less than the other, the date therein is before the other. Their lexical order is equal to their chronological order

        I agree that it’s a massive and unnecessary overhead that you should definitely avoid if possible, but for anything where this overhead is negligible it’s a very viable and safe way of storing date and time

        edit: I forgot, there’s also a format that’s output by functions like toUTCstring that’s totally different and doesn’t have any logical order, but I honestly forgot about that format because nobody in their right mind would use it