Skip to content

Commit

Permalink
improve hypothetical query
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmcsherry committed Jul 3, 2024
1 parent a809c9b commit 426ddf6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions posts/2024-05-19.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,16 +387,19 @@ We're going to start with something we haven't introduced yet, but it's a view w
-- All seconds within the past 24 hours.
CREATE VIEW moments AS
SELECT generate_series(
'1970-01-01 00:00:00+00',
'2099-01-01 00:00:00+00',
now() - '1 day'::interval + '1 second'::interval,
now(),
'1 second'
) moment
WHERE now() BETWEEN moment AND moment + '1 day';
) moment;
```

Unpacking this, `moments` contains rows with a single column containing a timestamp.
Whenever we look at it, the view contains those timestamps less or equal to `now()`, but at most three hours less.
It should have at any moment exactly 86,401 records present (SQL's `BETWEEN` is inclusive), roughly as many as `auctions` up above.
Whenever we look at it, the view contains those timestamps less than or equal to `now()`, but at most one day less.
It should have at any moment exactly 86,400 records present, as many as `auctions` up above.

Importantly, this view definition will not actually work for us.
You are welcome to try it out, but you'll find out that while it can be *inspected*, it cannot be *maintained*.
We'll fix that by the end of the post.

These moments are not auction data, though.
How do we get from moments to auctions and bids?
Expand Down

0 comments on commit 426ddf6

Please sign in to comment.