Thread: Implement a new data type

Implement a new data type

From
mohand oubelkacem makhoukhene
Date:
Hello

I would like to implement a new data type next to char, number, varchar... for example a special "Money" type, but
I don't want to use extensions and the Create type command.  I want to implement it directly inside source code,
because I want to implement my new type at lower level, in order to perform some more sophisticated functions after.
Just as an example,  help the optimizer in its decisions.
How should I proceed ? Is it an easy task ?

Thanks
Mohand

Re: Implement a new data type

From
Tom Lane
Date:
mohand oubelkacem makhoukhene <mohand-oubelkacem@outlook.com> writes:
> I would like to implement a new data type next to char, number, varchar... for example a special "Money" type, but
> I don't want to use extensions and the Create type command.  I want to implement it directly inside source code,
> because I want to implement my new type at lower level, in order to perform some more sophisticated functions after.

Why, and exactly what do you think you'd accomplish?

Postgres is meant to be an extensible system, which in general means that
anything that can be done in core code could be done in an extension.
Admittedly there are lots of ways that we fall short of that goal, but
new data types tend not to be one of them.  The only big difference
between an extension datatype and a core one is that for a core type
you have to construct all the catalog entries "by hand" by making
additions to the include/catalog/*.dat files, which is tedious and
error-prone.

> Just as an example,  help the optimizer in its decisions.

The core optimizer is pretty darn data-type-agnostic, and should
remain so IMO.  There are callbacks, such as selectivity estimators
and planner support functions, that contain specific knowledge of
particular functions and data types; and those facilities are available
to extensions too.

            regards, tom lane