PostgreSQL – DATA TYPES

PostgreSQL is a popular open-source relational database management system (RDBMS) that supports a wide range of data types to accommodate different kinds of data, from basic integers and text to more complex structures like arrays and JSON documents. Here are some of the common data types provided by PostgreSQL:

  1. Numeric Types:
    • integer (int): A 32-bit signed integer.
    • bigint: A 64-bit signed integer.
    • numeric or decimal: Arbitrary precision decimal number.
  2. Character Types:
    • char(n) or character(n): Fixed-length character string.
    • varchar(n) or character varying(n): Variable-length character string.
    • text: Variable-length character string with no limit.
  3. Binary Data Types:
    • bytea: Binary data, useful for storing binary files like images or documents.
  4. Date and Time Types:
    • date: Date (year, month, day).
    • time: Time of day (hour, minute, second).
    • timestamp: Date and time (including fractions of a second).
    • interval: Time interval.
  5. Boolean Type:
    • boolean: Represents true or false values.
  6. Enumerated Types:
    • enum: User-defined enumeration type.
  7. Geometric Types:
    • point: Represents a point in a two-dimensional space.
    • line: Represents an infinite line in a two-dimensional space.
    • lseg: Represents a line segment in a two-dimensional space.
    • box: Represents a rectangular box in a two-dimensional space.
    • path: Represents a path consisting of points connected by straight line segments.
    • polygon: Represents a closed polygonal path.
  8. Network Address Types:
    • inet: IPv4 or IPv6 network address.
    • cidr: IPv4 or IPv6 network address with a specified subnet mask.
  9. Text Search Types:
    • tsvector: Text search document.
    • tsquery: Text search query.
  10. UUID Type:
    • uuid: Universally Unique Identifier.
  11. JSON Types:
    • json: JSON data.
    • jsonb: Binary representation of JSON data, allowing for efficient querying.
  12. Array Types:
    • Arrays of various data types, such as integer[] or text[].
  13. Composite Types:
    • User-defined composite types.
  14. Range Types:
    • int4range, numrange, daterange, etc. Represent ranges of various data types.
  15. HStore Type:
    • hstore: A key-value store within a single PostgreSQL value.
  16. Domain Types:
    • User-defined data types based on other base data types.

These are just some of the data types available in PostgreSQL. Each data type has specific characteristics, storage requirements, and functions associated with it. You can use these data types to model and store your data effectively within PostgreSQL databases.

Similar Posts