Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Tuesday, 6 February 2024

PostgreSQL Data Types: A Comprehensive Guide

PostgreSQL offers a wide range of data types to accommodate various types of data, including integers, text, dates, arrays, JSON, and more. Below is a comprehensive guide to PostgreSQL data types:


 1. Numeric Types:


- Integer (INT, INTEGER): Stores whole numbers without decimal points.

- Serial: Auto-incrementing integer.

- Bigint: Stores large integers.

- Decimal/numeric: Exact numeric values with a user-specified precision and scale.

- Float, Real: Floating-point numbers with a specified precision.


 2. Character Types:


- Char(n): Fixed-length character strings.

- Varchar(n): Variable-length character strings with a maximum length.

- Text: Variable-length character strings with no specified length limit.


 3. Date/Time Types:


- Date: Stores date values (year, month, day).

- Time: Stores time values (hours, minutes, seconds).

- Timestamp: Stores date and time values.

- Interval: Represents a time span.


 4. Boolean Type:


- Boolean: Stores true/false values.


 5. Binary Data Types:


- Bytea: Stores binary data (e.g., images, documents).


 6. Array Types:


- Array: Stores arrays of any data type, including multi-dimensional arrays.


 7. Composite Types:


- Composite: User-defined data types composed of multiple fields.


 8. JSON and JSONB Types:


- JSON: Stores JSON data in text format.

- JSONB: Stores JSON data in a binary format for efficient storage and querying.


 9. Geometric Types:


- Point, Line, Lseg, Box, Path, Polygon, Circle: Stores geometric data.


 10. Network Address Types:


- Inet: Stores IPv4 and IPv6 network addresses.

- Cidr: Stores network addresses with subnet masks.


 11. UUID Type:


- UUID: Stores universally unique identifiers.


 12. XML Type:


- XML: Stores XML data.


 13. Enumerated Types:


- Enum: Defines a set of symbolic values.


 14. Range Types:


- Range: Represents a range of values of a specified data type.


 15. Custom Types:


- PostgreSQL allows users to define custom data types using the CREATE TYPE statement.


PostgreSQL provides a rich set of data types to suit various data storage and manipulation requirements. By choosing the appropriate data type for each column in your database schema, you can ensure data integrity, efficiency, and optimal performance in your PostgreSQL database applications. Always refer to the PostgreSQL documentation for detailed information on each data type and its usage.

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.