Skip to content

feat(postgres): add comprehensive PostgreSQL function support (array, network, UUID, hstore, range) - #26

Merged
vistart merged 5 commits into
release/v1.0.0.dev10from
feature/supplement-functions
Apr 10, 2026
Merged

vistart merged 5 commits into
release/v1.0.0.dev10from
feature/supplement-functions

Conversation

@vistart

@vistart vistart commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Description

Adds comprehensive PostgreSQL function support to the rhosocial-activerecord-postgres backend, supplementing the existing math, text search, and XML functions with new categories:

Array functions (18 functions):

  • Aggregation: array_agg, array_agg_distinct
  • Modification: array_append, array_prepend, array_cat, array_remove, array_replace
  • Inspection: array_dims, array_fill, array_length, array_lower, array_upper, array_ndims, array_position, array_positions
  • Conversion: array_to_string, string_to_array, unnest

Network address functions (16 functions):

  • Connection info: inet_client_addr, inet_client_port, inet_server_addr, inet_server_port
  • Operations: inet_merge, inet_and, inet_or, inetnot, inet_set_mask
  • Properties: inet_masklen, inet_netmask, inet_network, inet_recv, inet_show, cidr_netmask, macaddr8_set7bit

UUID functions (8 functions):

  • Generation: uuid_generate_v1, uuid_generate_v1mc, uuid_generate_v3, uuid_generate_v4, uuid_generate_v5
  • Constants: uuid_nil, uuid_max

Hstore functions (33 functions):

  • Construction: hstore_from_record, hstore_from_key_value
  • Key/value access: hstore_akeys, hstore_skeys, hstore_avals, hstore_svals, hstore_each
  • Conversion: hstore_to_array, hstore_to_matrix, hstore_to_json, hstore_to_jsonb, hstore_to_json_loose, hstore_to_jsonb_loose
  • Slicing/lookup: hstore_slice, hstore_exist, hstore_defined, hstore_get_value, hstore_get_values
  • Modification: hstore_delete, hstore_delete_keys, hstore_delete_pairs, hstore_concat
  • Containment: hstore_key_exists, hstore_all_keys_exist, hstore_any_key_exists, hstore_contains, hstore_contained_by
  • Subtraction: hstore_subtract_key, hstore_subtract_keys, hstore_subtract_pairs
  • Operators: hstore_to_array_operator, hstore_to_matrix_operator, hstore_record_update, hstore_subscript_get, hstore_subscript_set, hstore_populate_record

Range constructors (6 functions):

  • int4range, int8range, numrange, tsrange, tstzrange, daterange

Type of change

  • feat: A new feature
  • docs: Documentation only changes
  • perf: A code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • chore: Changes to the build process or auxiliary tools
  • ci: Changes to our CI configuration files and scripts
  • build: Changes that affect the build system or external dependencies
  • revert: Reverts a previous commit

Breaking Change

  • Yes
  • No

Applicable rhosocial-activerecord Version Range: >=1.0.0,<2.0.0

Related Repositories/Packages

None - this change is isolated to the postgres backend.

Testing

  • I have added new tests to cover my changes.
  • I have updated existing tests to reflect my changes.
  • All existing tests pass.
  • This change has been tested on PostgreSQL 16+.

Test Plan:

  • pytest tests/rhosocial/activerecord_test/feature/backend/postgres/test_postgres_array_functions.py
  • pytest tests/rhosocial/activerecord_test/feature/backend/postgres/test_postgres_network_functions.py
  • pytest tests/rhosocial/activerecord_test/feature/backend/postgres/test_postgres_uuid_functions.py
  • pytest tests/rhosocial/activerecord_test/feature/backend/postgres/test_postgres_range_constructors.py

Checklist

  • My code follows the project's code style guidelines.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation (Docstrings, README.md, etc.).
  • My changes generate no new warnings.
  • I have added a Changelog fragment (changelog.d/<issue_number>.<type>.md).
  • I have verified that my changes do not introduce SQL injection vulnerabilities.
  • I have checked for potential performance regressions.

Additional Notes

This PR renames hstore extraction functions with hstore_ prefix for naming consistency (commit 6f7404b). The range constructors were previously in range.py types module; this PR adds them as proper function exports in functions/.

vistart and others added 3 commits April 10, 2026 12:00
…tructors

New function modules:
- array.py: 17 array functions (array_agg, array_append, etc.)
- network.py: 15 network functions (inet_client_addr, inet_merge, etc.)
- uuid.py: 7 UUID functions (uuid_generate_v1, uuid_generate_v4, etc.)

Fix range constructors to use sentinel pattern for bounds parameter:
- int4range, int8range, numrange, tsrange, tstzrange, daterange
- Omit bounds when using default inclusive '[]', include when explicitly specified

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add PostgreSQL hstore extension functions including:
- Constructors: hstore_from_record, hstore_from_key_value
- Key/Value extraction: akeys, skeys, avals, svals, each
- Conversion: hstore_to_array, hstore_to_matrix, hstore_to_json,
  hstore_to_jsonb, hstore_to_json_loose, hstore_to_jsonb_loose
- Existence: hstore_exist, hstore_defined
- Delete: hstore_delete, hstore_delete_keys, hstore_delete_pairs
- Record: hstore_populate_record
- Operators: hstore_get_value, hstore_get_values, hstore_concat,
  hstore_key_exists, hstore_all_keys_exist, hstore_any_key_exists,
  hstore_contains, hstore_contained_by, hstore_subtract_*,
  hstore_to_array_operator, hstore_to_matrix_operator,
  hstore_record_update
- Subscript: hstore_subscript_get, hstore_subscript_set

Note: Generic function names (exist, delete, defined, slice,
populate_record, record_update) are prefixed with hstore_ to
avoid confusion with unrelated functionality.
…refix

Rename generic function names to avoid confusion:
- akeys → hstore_akeys
- skeys → hstore_skeys
- avals → hstore_avals
- svals → hstore_svals
- each → hstore_each

All hstore functions now consistently use the hstore_ prefix.
@vistart vistart self-assigned this Apr 10, 2026
@codecov

codecov Bot commented Apr 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.34944% with 69 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.98%. Comparing base (644956a) to head (2df451e).
⚠️ Report is 1 commits behind head on release/v1.0.0.dev10.

Files with missing lines Patch % Lines
...iverecord/backend/impl/postgres/functions/range.py 29.87% 33 Missing and 21 partials ⚠️
...iverecord/backend/impl/postgres/functions/array.py 85.41% 4 Missing and 3 partials ⚠️
...erecord/backend/impl/postgres/functions/network.py 90.00% 2 Missing and 2 partials ⚠️
...tiverecord/backend/impl/postgres/functions/uuid.py 81.81% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@                   Coverage Diff                    @@
##           release/v1.0.0.dev10      #26      +/-   ##
========================================================
+ Coverage                 72.93%   72.98%   +0.05%     
========================================================
  Files                       122      126       +4     
  Lines                      6924     7193     +269     
  Branches                   1144     1178      +34     
========================================================
+ Hits                       5050     5250     +200     
- Misses                     1471     1512      +41     
- Partials                    403      431      +28     
Flag Coverage Δ
postgres-18 72.98% <74.34%> (+0.05%) ⬆️
python-3.14 72.98% <74.34%> (+0.05%) ⬆️
unittests 72.98% <74.34%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

Copy link
Copy Markdown

@vistart
vistart merged commit 91f82bd into release/v1.0.0.dev10 Apr 10, 2026
14 checks passed
@vistart vistart mentioned this pull request Apr 12, 2026
4 of 12 tasks
vistart added a commit that referenced this pull request Apr 12, 2026
… network, UUID, hstore, range) (#26)

* feat(postgres): add array, network, UUID functions and fix range constructors

New function modules:
- array.py: 17 array functions (array_agg, array_append, etc.)
- network.py: 15 network functions (inet_client_addr, inet_merge, etc.)
- uuid.py: 7 UUID functions (uuid_generate_v1, uuid_generate_v4, etc.)

Fix range constructors to use sentinel pattern for bounds parameter:
- int4range, int8range, numrange, tsrange, tstzrange, daterange
- Omit bounds when using default inclusive '[]', include when explicitly specified

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(postgres): add comprehensive hstore function support

Add PostgreSQL hstore extension functions including:
- Constructors: hstore_from_record, hstore_from_key_value
- Key/Value extraction: akeys, skeys, avals, svals, each
- Conversion: hstore_to_array, hstore_to_matrix, hstore_to_json,
  hstore_to_jsonb, hstore_to_json_loose, hstore_to_jsonb_loose
- Existence: hstore_exist, hstore_defined
- Delete: hstore_delete, hstore_delete_keys, hstore_delete_pairs
- Record: hstore_populate_record
- Operators: hstore_get_value, hstore_get_values, hstore_concat,
  hstore_key_exists, hstore_all_keys_exist, hstore_any_key_exists,
  hstore_contains, hstore_contained_by, hstore_subtract_*,
  hstore_to_array_operator, hstore_to_matrix_operator,
  hstore_record_update
- Subscript: hstore_subscript_get, hstore_subscript_set

Note: Generic function names (exist, delete, defined, slice,
populate_record, record_update) are prefixed with hstore_ to
avoid confusion with unrelated functionality.

* refactor(postgres): rename hstore extraction functions with hstore_ prefix

Rename generic function names to avoid confusion:
- akeys → hstore_akeys
- skeys → hstore_skeys
- avals → hstore_avals
- svals → hstore_svals
- each → hstore_each

All hstore functions now consistently use the hstore_ prefix.

* chore: add changelog fragment for PR #26

* test(postgres): add hstore function tests for full coverage

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@vistart
vistart deleted the feature/supplement-functions branch May 30, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant