Skip to content

Instantly share code, notes, and snippets.

@weivall
Forked from karanlyons/partial_range_update.sql
Created April 25, 2020 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weivall/e580e9292404ab345356384b44b2dd31 to your computer and use it in GitHub Desktop.
Save weivall/e580e9292404ab345356384b44b2dd31 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