Implemented CRDTs v5
Currently, six CRDT data types are implemented:
- Grow-only counter and sum
- Positive-negative counter and sum
- Delta counter and sum
The counters and sums behave mostly the same, except that the counter types are integer based (bigint
), and the sum types are decimal based (numeric
).
You can list the currently implemented CRDT data types with the following query:
Grow-only counter (crdt_gcounter
)
Supports only increments with nonnegative values (
value + int
andcounter + bigint
operators).You can obtain the current value of the counter either using
#
operator or by casting it tobigint
.Isn't compatible with simple assignments like
counter = value
, which is a common pattern when the new value is computed somewhere in the application.Allows simple reset of the counter using the
!
operator (counter = !counter
).You can inspect the internal state using
crdt_gcounter_to_text
.
Grow-only sum (crdt_gsum
)
Supports only increments with nonnegative values (
sum + numeric
).You can obtain the current value of the sum either by using the
#
operator or by casting it tonumeric
.Isn't compatible with simple assignments like
sum = value
, which is the common pattern when the new value is computed somewhere in the application.Allows simple reset of the sum using the
!
operator (sum = !sum
).Can inspect internal state using
crdt_gsum_to_text
.
Positive-negative counter (crdt_pncounter
)
Supports increments with both positive and negative values through
counter + int
andcounter + bigint
operators.You can obtain the current value of the counter either by using the
#
operator or by casting tobigint
.Isn't compatible with simple assignments like
counter = value
, which is the common pattern when the new value is computed somewhere in the application.Allows simple reset of the counter using the
!
operator (counter = !counter
).You can inspect the internal state using
crdt_pncounter_to_text
.
Positive-negative sum (crdt_pnsum
)
Supports increments with both positive and negative values through
sum + numeric
.You can obtain the current value of the sum either by using the
#
operator or by casting tonumeric
.Isn't compatible with simple assignments like
sum = value
, which is the common pattern when the new value is computed somewhere in the application.Allows simple reset of the sum using the
!
operator (sum = !sum
).You can inspect the internal state using
crdt_pnsum_to_text
.
Delta counter (crdt_delta_counter
)
Is defined a
bigint
domain so works exactly like abigint
column.Supports increments with both positive and negative values.
Is compatible with simple assignments like
counter = value
, which is common when the new value is computed somewhere in the application.There's no simple way to reset the value reliably.
Delta sum (crdt_delta_sum
)
Is defined as a
numeric
domain so works exactly like anumeric
column.Supports increments with both positive and negative values.
Is compatible with simple assignments like
sum = value
, which is common when the new value is computed somewhere in the application.There's no simple way to reset the value reliably.