WalzoneInterview Prep
πŸ“ž Interviewing soon? Practice with a realistic AI mock phone interview β€” it calls you, then scores you. First 15 min FREE β†’

PostgreSQL Β· Basic Β· question 6 of 100

What are the basic data types available in PostgreSQL?

πŸ“• Buy this interview preparation book: 100 PostgreSQL questions & answers β€” PDF + EPUB for $5

PostgreSQL supports several data types, including but not limited to:

1. Numeric Data Types:

- Integer (int): a whole number of varying sizes depending on the range needed (e.g., integer, smallint, bigint)

- Floating-point numbers: values with decimal points with varying ranges and precisions (e.g., float, decimal, numeric)

- Serial: a type of integer that automatically increments as values are added to a column

2. Character Data Types:

- Char (character): a fixed-length string of characters

- Varchar (variable character): a string of characters with varying length

3. Date and Time Data Types:

- Date: a date value (e.g., YYYY-MM-DD)

- Time: a time value (e.g., HH:MM:SS)

- Timestamp: a date and time value (e.g., YYYY-MM-DD HH:MM:SS)

- Interval: a period of time (e.g., 20 minutes)

4. Boolean Data Type:

- Boolean: true or false values

5. Array Data Type:

- Array: a collection of values of the same data type

6. Composite Data Types:

- Row: a collection of values of different data types

Examples of creating tables with different data types in Java:

import java.sql.*;

public class PostgresConnect {
   public static void main(String[] args) {
      final String url = "jdbc:postgresql://localhost/testdb";
      final String user = "postgres";
      final String password = "password";

      try (Connection conn = DriverManager.getConnection(url, user, password);
         Statement statement = conn.createStatement()) {
         
         String createTableQuery = "CREATE TABLE demo_table " +
               "(id SERIAL PRIMARY KEY, " +
               "name VARCHAR(255), " +
               "age INT, " +
               "dob DATE)";
               
         statement.executeUpdate(createTableQuery);         
      } catch (SQLException e) {
         System.out.println("Connection failure.");
         e.printStackTrace();
      }
   }
}

This example creates a table called "demo_table" with four columns: "id" of type serial (an auto-incrementing integer), "name" of type varchar with a length of 255 characters, "age" of type integer, and "dob" of type date.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic PostgreSQL interview β€” then scores it.
πŸ“ž Practice PostgreSQL β€” free 15 min
πŸ“• Buy this interview preparation book: 100 PostgreSQL questions & answers β€” PDF + EPUB for $5

All 100 PostgreSQL questions Β· All topics