Menu

#1847 (ok 3.0) columns can not have empty string as default

2.6.4-pl3
fixed
1
2013-06-11
2005-11-01
No

when alter/create table a new field does/can not have
an empty string as default value

also in table structure view there is no difference
between an empty string as default or no default set at all

Discussion

  • Michal Čihař

    Michal Čihař - 2005-11-03

    Logged In: YES
    user_id=192186

    Doesn't MySQL silently set empty default (for string) or 0
    (for numbers) if no default is set? Otherwise we would need
    some checkbox whether to use default value.

     
  • Sebastian Mendel

    Logged In: YES
    user_id=326580

    no, at least not in strict mode

    and so MySQL 5 strict complaints about an insert with no
    value for a field without a default value

     
  • Michal Čihař

    Michal Čihař - 2005-11-03

    Logged In: YES
    user_id=192186

    Okay, this is probably something for next release as we've
    translation freeze right now and it would require new message.

     
  • Marc Delisle

    Marc Delisle - 2005-11-08
    • priority: 5 --> 4
     
  • Sebastian Mendel

    Logged In: YES
    user_id=326580

    can we change the default input field that users have to use
    '' to enclose strings?

    making it possbile to enter empty strings: ''
    making it possible to enter: CURRENT_TIMESTAMP, NULL,
    CURRENT_TIMESTAMP() or NOW()

     
  • Michal Čihař

    Michal Čihař - 2005-12-15

    Logged In: YES
    user_id=192186

    IMHO forcing user to add quotes and escape string is not
    good way.

    I'd choose adding select for NULL/empty values.

     
  • Marc Delisle

    Marc Delisle - 2005-12-21

    Logged In: YES
    user_id=210714

    Why don't we force in the generated CREATE TABLE and ALTER
    TABLE, a DEFAULT clause containing the appropriate value
    (empty string or 0) depending on the field type, when there
    is no default value coming from the GUI?

    This should work, except for ENUM/SET where the default
    value must be one of the list.

     
  • Sebastian Mendel

    Logged In: YES
    user_id=326580

    any field type can have null as default,

    for numeric fields this is not a problem empty means null
    and any other value is casted to numeric value

    but with text this is not so easy an empty value could mean
    null or empty - how should PMA decide?

     
  • Matt Whitlock

    Matt Whitlock - 2006-04-10

    Logged In: YES
    user_id=1159156

    This was my suggestion that I made in a comment of bug
    #1467709 (which I would contend is not really a duplicate
    of this bug, since it had more to do with the error that
    PMA receives when it incorrectly tries to interpret a
    blank default value as an empty string, even for numeric
    and date types):

    The phpMyAdmin team might consider adding checkboxes next
    to the default value fields in the edit table structure
    page. If checked, the field would be editable, and the
    corresponding column would be given the specified default
    value. If not checked, the field would be cleared and
    disabled, and the corresponding column would not be given
    a default value.

     
  • Matt Whitlock

    Matt Whitlock - 2006-04-10

    Logged In: YES
    user_id=1159156

    For TEXT and BLOB type columns, this is a non-issue
    because they can't have default values anyway. For INT
    and DATE type columns, this is a non-issue because they
    can't have empty/blank default values, so an empty default
    value can just be interpretted as NULL or no default
    value, depending on the nullability of the column.

    But, this is a big issue for CHAR/VARCHAR columns. In the
    case of a CHAR NOT NULL column, does an empty default
    value field mean that the default value should be the
    empty string or should there be no default value at all?
    In the case of a CHAR NULL column, does an empty default
    value field mean that the default value should be the
    empty string or should it be NULL? Likewise, does the
    text "null" in the default value field mean the default
    value should be the string "null" or should it be the NULL
    value?

    In short, there definitely needs to be a checkbox to
    say "I want to give this column this default value."
    Unchecked for NULL columns means default value is NULL.
    Unchecked for NOT NULL columns means no default value is
    defined.

     
  • Matt Whitlock

    Matt Whitlock - 2006-04-10

    Logged In: YES
    user_id=1159156

    Incidentally, (this should be obvious, but I'll say it
    anyway), you don't have to say DEFAULT NULL in the SQL
    query. You can just leave the DEFAULT clause out
    entirely. So it's really easy to implement the checkbox.
    If the box is checked, you have a DEFAULT clause in the
    query. If it's not checked, you don't.

     
  • Sebastian Mendel

    Logged In: YES
    user_id=326580
    Originator: YES

    fixed in svn trunk, will be in 3.0

    test here:

    http://pma.cihar.com/trunk-config/

     
  • Sebastian Mendel

    • labels: --> Data insertion/extraction/manipulation
    • assigned_to: nobody --> cybot_tm
    • summary: create/alter table new field can not have empty string as de --> (ok 3.0) columns can not have empty string as default
    • priority: 4 --> 1
    • status: open --> open-fixed
     
  • Marc Delisle

    Marc Delisle - 2008-09-27
    • status: open-fixed --> closed-fixed
     
  • Michal Čihař

    Michal Čihař - 2013-06-11
    • Status: closed-fixed --> fixed