Beyond Conventional Data Types

PostgreSQL can handle rich data types due to its powerful extensions. Data that does not fit the relational model inherently, such as semi-structured data, can be stored and manipulated, either using out-of-the-box data types or extensions. Also, the PostgreSQL community focuses not only on enhancing relational database features, but also on supporting rich data types such as arrays, XMLs, hash stores, and JSON documents. The focus shift is a result of embracing changes in the software development process's life cycle, such as agile development methods, and supporting unknown and rapid software requirements.

Non-conventional data types allow PostgreSQL to store different data types such as geographical, binary, as well as schema-less data, such as JSON documents and hash stores. PostgreSQL supports some of these data types out of the box, including JSON, JSONB, XML, array, byte, and BLOB. More data types are available via extensions such as hstore and PostGIS.

JSON, JSONB, and HStore allow PostgreSQL to handle schema-less models, which in turn allow developers to make real-time adjustments to data in an automatic and transparent way. Using JSON, JSONB, and hstore allows developers to change the data structure without changing the table structure using the ALTER command. Also, it allows them to have a flexible data model without using the entity-attribute-value (EAV) model, which is difficult to handle in the relational model. However, developers should take care handling data integrity in the business logic to ensure that the data is clean and error free.

In this chapter the following data types will be covered: 

  •  Array datatype.
  • Hstore datatype which is used as a key/value store.
  • JSON datatype
  • Full text search datatypes including tsquery and tsvector. 

It would be nice to have a look also at the PostGIS extension, knowing that PostGIS supports raster and vector formats, and provides very rich functions to manipulate data. Other interesting datatype is range datatype which can be used in defining range interval such as date range.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset