Skip to content

Zero times are NULL, and query keys have two or more parts - #52

Merged
djthorpe merged 4 commits into
masterfrom
djt/1119/zero-time-null
Nov 19, 2026
Merged

djthorpe merged 4 commits into
masterfrom
djt/1119/zero-time-null

Conversation

@djthorpe

@djthorpe djthorpe commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Two fixes for the next release.

A zero time.Time is NULL, and NULL scans into a zero time.Time

A nullable timestamp column can now be read and written as a plain time.Time, without a pointer or a helper.

  • Binding: a zero time.Time binds as NULL, not 0001-01-01T00:00:00Z.
  • Scanning: NULL into a time.Time is the zero time, not an error. NULL into a *time.Time is still nil, and into other non-pointer values, such as a string, is still an error.
  • Behaviour change: a zero time written to a NOT NULL column is now a constraint error. Before, it was stored as year 1. filesearch's tests inserted two objects without a modtime, so they now set one. Rows that already hold 0001-01-01T00:00:00Z still read back as the zero time.

Saved query keys have two or more parts (closes #51)

  • Keys: a key is now x.y, or longer. A comment line of one word, such as -- change, is an ordinary comment. Before, it started a new key and left the previous key with an empty statement.
  • Empty statements: a key without a statement is an error from NewQueries, so this can't fail silently again.
  • Breaking: a file with one-part keys, such as -- credential, needs its keys renamed before upgrading. go-auth's credential/pg/schema/objects.sql has one, but it uses go-pg, which has the same fix in go-pg #138.

…e zero time

So a nullable timestamp column round-trips a time.Time without a pointer.
filesearch's tests now give objects a modtime, as its column is NOT NULL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 08:21
@djthorpe djthorpe self-assigned this Nov 19, 2026
djthorpe and others added 2 commits November 19, 2026 09:23
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n error

So a one-word comment line, such as "-- change", isn't read as a key, which
left the key before it without its statement. Closes #51.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Coverage for this change: 90.7%

@djthorpe djthorpe changed the title A zero time.Time is NULL, and NULL scans into a zero time.Time Zero times are NULL, and query keys have two or more parts Nov 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Zero-time handling can cause existing index entries to be deleted during reindexing and applies NULL conversion inconsistently between time values and pointers.

2 open issues
What changed in this PR

Updates the shared value-conversion layer so nullable timestamps can use plain time.Time values without pointers or helpers.

Changes:

  • Binds zero time.Time values as SQL NULL and scans NULL into zero times.
  • Adds conversion tests and supplies nonzero modification times in two filesearch test fixtures.
  • Documents the new timestamp behavior.
File Description
values/​values_test.go Tests zero-time binding and NULL-to-time scanning.
values/​set.go Converts zero time.Time values to NULL.
values/​scan.go Allows NULL to scan into time.Time.
README.md Documents nullable timestamp conversions.
filesearch/​schema/​schema_test.go Supplies modification times required by NOT NULL constraints.

Review effort: Balanced

Comment thread values/set.go Resolved
Comment thread values/set.go Resolved
…ch stores a zero modtime as text

filesearch's modtime is NOT NULL, and an fs.FS can have no modification
times, so it binds the time's text, which is matched when the object is
marked, rather than NULL, which isn't, and would have it swept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@djthorpe
djthorpe merged commit dde207c into master Nov 19, 2026
2 checks passed
@djthorpe
djthorpe deleted the djt/1119/zero-time-null branch November 19, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Saved queries: a one-word comment line is read as a query key

2 participants