i think a lot of contrib updates get this wrong, and what they think is valid for pgsql support in fact throws errors. i've personally run into this 2 times, and there are probably a lot of others. the attached patch attempts to clarify the doxygen comments for this function, so that http://api.drupal.org/api/4.7/function/db_add_column will be more useful. basically, if you want a NOT NULL string field, you have to use:

array('not null' => TRUE, 'default' => "''")

as your $attributes array. a lot of people (including myself, after first reading the docs) think this works:

array('not null' => TRUE, 'default' => '')

thanks,
-derek

CommentFileSizeAuthor
db_add_column-doc.patch1.51 KBdww

Comments

dries’s picture

Status: Needs review » Fixed

Committed to HEAD.

I think this is a good example of why database abstraction layers are bad. It takes you 10 minutes to figure out how that NOT NULL is specified as ''.

dww’s picture

i disagree. ;) if we had an abstration layer, and everyone knew how to use it, there wouldn't be god-knows-how-many updates that are broken on pgsql that i'm going to run into as i start really trying to use pgsql. instead, everyone writes to mysql-aware sql, which is all they ever test, and pgsql remains broken. :(

(any reason not to apply this in DRUPAL-4-7?)

thanks for the quick commit, at least. ;)

-derek

Anonymous’s picture

Status: Fixed » Closed (fixed)