postgres-extension.rs icon indicating copy to clipboard operation
postgres-extension.rs copied to clipboard

Datum

Open thehydroimpulse opened this issue 10 years ago • 1 comments

Need to figure out a good story here. A datum is simply a pointer stored as a uint. Then casted to an appropriate type (in C). Text, for example, is allocated onto the heap using the custom pg_malloc allocator that allocates memory in contexts (regions). This enables it to easily clean up after a misbehaving extension, for example, in one whole swoop, instead of keeping track of a bunch of independent allocations that could never be freed.

Ideally, one could simply do:

Datum::new("foobar");
Datum::new(5i);
Datum::new(true);

Postgres has the concept of:

  • Pass by-value using a fixed length.
  • Pass by-reference using a fixed length.
  • Pass by-reference using a variable length.

thehydroimpulse avatar Oct 18 '14 06:10 thehydroimpulse

Looking through the source, I noticed that Datum.val defaults to 0. Should this be updated to make use of the new non-zero numeric types?

timClicks avatar Mar 28 '18 15:03 timClicks