Skip to content

Instantly share code, notes, and snippets.

@karanlyons
Last active September 16, 2022 15:11
Show Gist options
  • Save karanlyons/3af10ad9a90dbbd02a6b to your computer and use it in GitHub Desktop.
Save karanlyons/3af10ad9a90dbbd02a6b to your computer and use it in GitHub Desktop.
Postgres: Update only portion of range, preserving other half and bounds.
UPDATE <TABLE> SET
<COLUMN>=<RANGE_TYPE>(
lower(<COLUMN>), -- Swap out for actual value
upper(<COLUMN>), -- Swap out for actual value
concat(
CASE WHEN lower_inc(<COLUMN>) THEN '[' ELSE '(' END,
CASE WHEN upper_inc(<COLUMN>) THEN ']' ELSE ')' END
)
)
WHERE <CONDITION>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment