Search code examples
cpostgresqlextend

What is the difference in the extension of postgres?


I want to create a new data type and new operators in PostgreSQL. I saw that in the documentation, it is possible to incorporate new source files in C (for example) and create a new data type and operators. PostgreSQL is extensible in that direction. More information at: documentation

But also the PostgreSQL has open source, and I could alter the source code and add a new data type, compiling a new version.

With that, I want to know what the differences, advantages and disadvantages of each method of including a new data type in PostgreSQL. I'm very concerned about the performance in query processing. Thank you.


Solution

  • I fully agree with Jachim's answer. Another thing is:

    Developing your own C-Language extension in PostgreSQL is (rather) well documented - simple programs can be done by compiling just one function of code and writing the corresponding functions. Adding a custom datatype is a bit more complicated, but still doable. The extension I developed was even written in C++ with just a bit of wrapper glue between PostgreSQL's plain C - that made developing much more flexible.

    Altering the PostgreSQL core however is more complicated in terms of how do you start and what do you do. And in the end, you archive the same.

    To sum it up: C-Language functions gives you all the advantages:

    • High performance by utilising PostgreSQLs internal datatypes
    • Simple programming interface
    • Just a small bit of code with a documented and presumably very stable function interface

    I can not see any advantages of altering PostgreSQLs core, but many disadvantages:

    • Long compilation times
    • Maintaining your own code branch and regularly reapplying your patch to the current release
    • Higher risk of bugs.

    If you need an example of a lot of different ways to use the C-Language interface, have a look at the PostGis source code - they use nearly all function types and have a lot of fancy tricks in their code.