Skip to content

feat(system): environment() table function (S9) - #94

Merged
TimelordUK merged 1 commit into
mainfrom
feat/s9-environment
Sep 27, 2026
Merged

TimelordUK merged 1 commit into
mainfrom
feat/s9-environment

Conversation

@TimelordUK

Copy link
Copy Markdown
Owner

Summary

Adds environment() beside processes() and sockets(): one row per environment variable the sql-cli process inherited.

SELECT * FROM environment() WHERE UPPER(name) LIKE 'CARGO%';

WITH e AS (SELECT value FROM environment() WHERE UPPER(name) = 'PATH')
SELECT UNNEST(value, ';') AS directory FROM e;   -- ':' on Unix
  • Columns name, value; the same on every platform, sorted case-insensitively by name.
  • Windows' hidden per-drive =C: variables are skipped.
  • An empty value stays '' rather than NULL, because on Unix set-but-empty is different from unset.
  • Non-UTF-8 values are converted lossily, never dropped.
  • Named environment() rather than env() to keep ENV('X') free for a scalar lookup.
  • Portability: Windows stores names case-insensitively, and the spelling follows the launching shell (Path from PowerShell, PATH from Git Bash). Use UPPER(name) in portable queries.

Docs: S9 in docs/SYSTEM_TABLES.md; examples in examples/system_environment.sql.

Test plan

  • Unit test environment_lists_what_this_process_inherited passes on Windows 11 and on Linux (WSL2); all system tests pass on Linux
  • On Linux, FOO= returns '' with length 0, and PATH splits on :
  • cargo clippy: no new warnings
  • ./run_all_tests.sh passes. One smoke test, expander_rewriters, fails on a GROUP BY error; it also fails without this change.

🤖 Generated with Claude Code

… (S9)

One row per inherited variable: name, value, sorted case-insensitively by
name. Same two columns on every platform, behind the system-tables feature.

- Windows' hidden per-drive `=C:` variables are skipped (not configuration,
  no Linux equivalent - the S1 "same kind of row?" rule).
- An empty value stays '' rather than NULL: on Unix set-but-empty differs
  from unset.
- Non-UTF-8 values are converted lossily, never dropped.
- Named environment() rather than env() to keep ENV('X') free for a scalar.

Documented in docs/SYSTEM_TABLES.md, including that Windows name case
follows the launching shell (Path from PowerShell, PATH from Git Bash).
Verified on Windows 11 and Linux (WSL2).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@TimelordUK
TimelordUK merged commit b0f49f4 into main Sep 27, 2026
8 checks passed
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.

1 participant