Uploaded image for project: 'DdlUtils'
  1. DdlUtils
  2. DDLUTILS-73

SQL syntax bug in PostgreSQL 8.1 for ALTER COLUMN

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.0 RC1
    • Core - PostgreSql
    • None
    • PostgreSQL 8.1

    Description

      The following code has to be added to PostgreSQLBuilder class to make it work for altering columns in PostgreSQL

      /**

      • Generates the alter statement to add or modify a single column on a table.
        *
      • @param table The table the index is on
      • @param column The column to drop
      • @param isNewColumn Whether the column should be added
        */
        public void writeColumnAlterStmt(Table table, Column column, boolean isNewColumn) throws IOException { writeTableAlterStmt(table); print(isNewColumn ? "ADD " : "ALTER "); if(isNewColumn) writeColumn(table, column); else writeAlterColumn(table, column); printEndOfStatement(); }

      /**

      • Outputs the DDL for the specified column.
      • @param table The table containing the column
      • @param column The column
        */
        protected void writeAlterColumn(Table table, Column column) throws IOException
        {
        //see comments in columnsDiffer about null/"" defaults
        printIdentifier(getColumnName(column));
        print(" TYPE ");
        print(getSqlType(column));

      if ((column.getDefaultValue() != null) ||
      (getPlatformInfo().isIdentitySpecUsesDefaultValue() && column.isAutoIncrement()))
      {
      if (!getPlatformInfo().isSupportingDefaultValuesForLongTypes() &&
      ((column.getTypeCode() == Types.LONGVARBINARY) || (column.getTypeCode() == Types.LONGVARCHAR)))

      { throw new DynaSqlException("The platform does not support default values for LONGVARCHAR or LONGVARBINARY columns"); }

      print(" DEFAULT ");
      writeColumnDefaultValue(table, column);
      }
      if (column.isRequired())

      { print(" "); writeColumnNotNullableStmt(); }

      else if (getPlatformInfo().isRequiringNullAsDefaultValue() &&
      getPlatformInfo().hasNullDefault(column.getTypeCode()))

      { print(" "); writeColumnNullableStmt(); }

      if (column.isAutoIncrement() && !getPlatformInfo().isIdentitySpecUsesDefaultValue())
      {
      if (!getPlatformInfo().isSupportingNonPKIdentityColumns() && !column.isPrimaryKey())

      { throw new DynaSqlException("Column "+column.getName()+" in table "+table.getName()+" is auto-incrementing but not a primary key column, which is not supported by the platform"); }

      print(" ");
      writeColumnAutoIncrementStmt(table, column);
      }
      }

      Attachments

        Activity

          People

            tomdz Thomas Dudziak
            vigneshs Vignesh Swaminathan
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: