public class CreateTable extends PostgresSqlPart

Generates a CREATE TABLE statement for PostgreSQL.


Sample Generated SQL:

CREATE TABLE IF NOT EXISTS "table_name" (
  "user_id" serial,
  "email" text,
  PRIMARY KEY ("user_id")
);
  • Constructor Details

    • CreateTable

      public CreateTable()
    • CreateTable

      public CreateTable(String tableName)
  • Method Details

    • setPretty

      public CreateTable setPretty(boolean pretty)
      Indicates if line breaks and indentations should be added to output DDL (default false).

      Example output (pretty = true):
      CREATE TABLE IF NOT EXISTS "table_name" (
        "user_id" serial,
        "email" text
        PRIMARY KEY ("user_id")
      )

      Example output (pretty = false):
      CREATE TABLE IF NOT EXISTS "table_name" ("user_id" serial, "email" text, PRIMARY KEY ("user_id"))
      Overrides:
      setPretty in class SqlPart
    • collectSqlFragment

      public void collectSqlFragment(CodeWriter writer)
      Description copied from class: SqlPart
      Writes this part's SQL to the writer; used by SqlPart.getSqlFragment() and by enclosing parts.
      Specified by:
      collectSqlFragment in class SqlPart
    • getTableName

      public String getTableName()
    • setTableName

      public CreateTable setTableName(String tableName)
    • isCheckIfNotExists

      public boolean isCheckIfNotExists()
      Indicates if IF NOT EXISTS clause should be included in the CREATE TABLE statement (default true).
    • setCheckIfNotExists

      public CreateTable setCheckIfNotExists(boolean checkIfNotExists)
      Indicates if IF NOT EXISTS clause should be included in the CREATE TABLE statement (default true).
    • getColumns

      public List<CreateTableColumn> getColumns()
    • setColumns

      public CreateTable setColumns(List<CreateTableColumn> columns)
    • addColumn

      public CreateTable addColumn(CreateTableColumn column)
    • getPrimaryKeyColumns

      public List<CreateTableColumn> getPrimaryKeyColumns()
      Returns the columns marked as primary key, in column order; they form the table's PRIMARY KEY clause.