0

How did Postgres extend to accommodate PostGIS data types?

I am trying to create a spatial system. All the code is written in C++. I do not want to create separate data type in Postgres using CREATE TYPE command.

Is there a way using bytea or any other stuff that I can directly store my instances in Postgres.

I also have some methods I want to define on the C++ data types, is there a way to achieve this without operator class and CREATE FUNCTION command?

  • 1
    have you looked at the source? – Jasen Nov 3 '18 at 5:11
  • 2
    When you run create extension postgis it actually executes a SQL script in the background (postgis.sql located in the extension folder) - which in turn contains the necessary create type statements. If you want to create a new type, the only way to do that is to run create type - unless you patch the Postgres source code and compile a version for yourself – a_horse_with_no_name Nov 3 '18 at 9:23
0

Is there a way using bytea or any other stuff that I can directly store my instances in Postgres.

Yes, sure you can store anything as bytea. However, don't expect the database to know how to work with it. PostGIS is an extensive system that creates types, operators, access methods, indexes, and a slew of other stuff. You'll have to recreate all of that stuff for your type.

Alternatively, you can create something that reads a PostGIS types and experts one of your own types. This would be a C function. you can then create a cast from PostGIS's type, to your type and call all of your stuff -- your library -- working only on your native implementation.

This allows you to use all that is in PostGIS, and then still access all of the functionality you've got at the cost of a cast.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.