Add not null column in a table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bogie
    New Member
    • Aug 2007
    • 10

    Add not null column in a table

    Hi again

    I have another question, I would like to add NOT NULL column in my table. I have done like this :

    ALTER TABLE patent ALTER COLUMN patent_pri_date SET NOT NULL;

    but it doesn't work and give the following error :
    ERROR: ALTER TABLE: Attribute "patent_pri_dat e" contains NULL values

    is any body can help me how can i add NOT NULL column to my table ?, I use postgresql 7.4. Thank you very much.

    Best regards,
    Bogie
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    Originally posted by bogie
    Hi again

    I have another question, I would like to add NOT NULL column in my table. I have done like this :

    ALTER TABLE patent ALTER COLUMN patent_pri_date SET NOT NULL;

    but it doesn't work and give the following error :
    ERROR: ALTER TABLE: Attribute "patent_pri_dat e" contains NULL values

    is any body can help me how can i add NOT NULL column to my table ?, I use postgresql 7.4. Thank you very much.

    Best regards,
    Bogie

    I looks like there are rows in which pri_date column contans NULLS values. U should fill it first.

    Comment

    • amitpatel66
      Recognized Expert Top Contributor
      • Mar 2007
      • 2358

      #3
      Originally posted by bogie
      Hi again

      I have another question, I would like to add NOT NULL column in my table. I have done like this :

      ALTER TABLE patent ALTER COLUMN patent_pri_date SET NOT NULL;

      but it doesn't work and give the following error :
      ERROR: ALTER TABLE: Attribute "patent_pri_dat e" contains NULL values

      is any body can help me how can i add NOT NULL column to my table ?, I use postgresql 7.4. Thank you very much.

      Best regards,
      Bogie
      You can add NOT NULL columns to a table only if the table is EMPTY and does not contain any ROW.

      Comment

      • rski
        Recognized Expert Contributor
        • Dec 2006
        • 700

        #4
        Originally posted by amitpatel66
        You can add NOT NULL columns to a table only if the table is EMPTY and does not contain any ROW.
        I in version 8.* u can add not null on a column if it does not contain null values. Maybe I'm wrong but in earlier versions it's looks the same.

        Comment

        • henryhcface
          New Member
          • Sep 2007
          • 15

          #5
          attention......
          attention......
          attention......
          attention......
          attention......

          Comment

          • amitpatel66
            Recognized Expert Top Contributor
            • Mar 2007
            • 2358

            #6
            Originally posted by rski
            I in version 8.* u can add not null on a column if it does not contain null values. Maybe I'm wrong but in earlier versions it's looks the same.
            Yes It is possible to make the COLUMN NOT NULL in case if it does not contain any NULL value

            Comment

            • bogie
              New Member
              • Aug 2007
              • 10

              #7
              Originally posted by rski
              I looks like there are rows in which pri_date column contans NULLS values. U should fill it first.

              Hi

              Thank you very much for the advice, it works.

              Best regards,
              Bogie

              Comment

              Working...