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

Friday, 16 February 2024

Different Data types in PostgreSQL

In PostgreSQL, there are various data types that you can use to define columns in your database tables. Here is a list of some commonly used data types in PostgreSQL along with examples:

1. Integer Types:

   - INTEGER or INT: Integer data type (4 bytes).

   CREATE TABLE ExampleTable (

       ID INTEGER

   );

   - BIGINT: Big integer data type (8 bytes).

   CREATE TABLE ExampleTable (

       ID BIGINT

   );

2. Numeric Types:

   - DECIMAL: Fixed precision and scale numeric data type.

   CREATE TABLE ExampleTable (

       Price DECIMAL(10, 2)

   );

   - FLOAT or REAL: Floating-point number data type.

   CREATE TABLE ExampleTable (

       Price FLOAT

   );

3. Character Types:

   - VARCHAR: Variable-length character data type.

   CREATE TABLE ExampleTable (

       Name VARCHAR(50)

   );

   - CHAR: Fixed-length character data type.

   CREATE TABLE ExampleTable (

       Initial CHAR(1)

   );

4. Text Types:

   - TEXT: Variable-length character data type for large text values.

   CREATE TABLE ExampleTable (

       Description TEXT

   );

5. Date and Time Types:

   - DATE: Date data type.

   CREATE TABLE ExampleTable (

       BirthDate DATE

   );

   - TIMESTAMP or TIMESTAMP WITHOUT TIME ZONE: Date and time data type.

   CREATE TABLE ExampleTable (

       LastUpdate TIMESTAMP

   );

6. Boolean Type:

   - BOOLEAN: Boolean data type.

   CREATE TABLE ExampleTable (

       IsActive BOOLEAN

   );

7. Binary Types:

   - BYTEA: Binary data type.

   CREATE TABLE ExampleTable (

       BinaryData BYTEA

   );

8. JSON Type:

   - JSON: Stores JSON data.

   CREATE TABLE ExampleTable (

       UserData JSON

   );

9. UUID Type:

   - UUID: Stores universally unique identifier data.

   CREATE TABLE ExampleTable (

       GUIDColumn UUID

   );

These are just some of the data types available in PostgreSQL. Depending on your requirements, you may choose different data types to define columns in your database tables.

No comments:

Post a Comment

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