Blog Pages

PostgreSQL Data Types

“Standard” types
  • numeric, floating-point
  • string
  • Boolean
  • date/time
  • UUID
    • Universally Unique Identifies.
    • 16 bytes of storage.
    • Example: d5f28c97-b962-43be-9cf8-ca1632182e8e
  • XML
    • XML type is just a text data type.
    • The advantage is that it checks that the XML is well-formed.
  • json, jsonB
  • Text Search Type:
    • Two data types which are designed to support full-text search.
  • Money

Special Data types
  • Network Address
    • Network information like IP address.
    • Using Network Address Types has following advantages
      • Storage Space Saving
      • Input error checking
      • Functions like searching data by subnet
  • Geometric
    • Represent two-dimensional spatial objects.
    • They help perform operations like rotations, scaling, translation, etc.
  • Enumerated
    • A set of values. 
    • While inserting, it checks that the value is from the declared set.
    • The ordering of the values in an enum type is the order in which the values were listed when the type was created.
    • Example:
      • ('sad', 'ok', 'happy’);
      • In this example: ‘ok’ > ‘sad’ and < ‘happy’.
  • Range
    • Data in ranges.
    • Can be a range of numeric and dates.
  • Pseudo-Types
    • special-purpose entries.
    • Any, An array, Any element, Any enum, Nonarray, Cstring, Internal, Language_handler, Record, Trigger.

Custom data types - Composite Types
PostgreSQL user has the ability to create his own data types based on existing ones (composite types, ranges, arrays, enumerations).

CREATE TYPE inventory_item AS (name text, id integer)

SELECT item.name FROM on_hand WHERE item.price > 9.99;

INSERT INTO mytab (complex_col) VALUES((1.1,2.2));

UPDATE mytab SET complex_col = ROW(1.1,2.2) WHERE ...;



More about PostgreSQL data types: https://www.guru99.com/postgresql-data-types.html

No comments:

Post a Comment