If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

explain usage of bz_add_column's init_value parameter relative to DEFAULT clause

NEW
Unassigned

Status

()

Bugzilla
Bugzilla-General
13 years ago
8 years ago

People

(Reporter: myk, Unassigned)

Tracking

Details

(Reporter)

Description

13 years ago
myk	mkanat: in bz_add_column, what's init_value for?
	mkanat	myk: Ahh. :-)
	myk	mkanat: doesn't it duplicate the functionality of DEFAULT?
	mkanat	myk: It's for setting an initial value for columns that are NOT NULL and
have no DEFAULT.
	mkanat	myk: Standard SQL databases don't actually allow you to create a NOT
NULL column with no DEFAULT, it's just a fluke that MySQL does.
	myk	mkanat: shouldn't we just enforce the standard SQL restriction and write
that value into the DEFAULT clause of the column creation statement?
	mkanat	myk: Do the POD docs not actually explain that?
	mkanat	myk: The problem is that that fills checksetup with "bz_add_column" with
a "bz_alter_column" immediately afterward.
	myk	mkanat: the docs say what it is, but they don't say why it is
	mkanat	myk: It's much simpler, code-wise and for the caller, to have $init_value.
	mkanat	myk: Ahh. Perhaps the docs should be clearer.
	myk	mkanat: so does $init_value just get inserted into the DEFAULT clause?
	mkanat	myk: No, it gets set with an UPDATE.
	mkanat	myk: You could have something different in $init_value that you have in
DEFAULT.
	mkanat	*than
	myk	mkanat: why would you want that?
	mkanat	myk: Well, say you have a field that you want to default to TRUE for all
old entries, but FALSE for all new ones.
	mkanat	myk: Like how already_wrapped worked.
	myk	mkanat: how can there be old entries in a new column?
	mkanat	myk: Because the table already exists.
	myk	mkanat: so then DEFAULT would apply to new entries, and init_value would
apply to old ones?
	mkanat	myk: Yeah.
	mkanat	myk: That's really a sort of niche usage, though.
	mkanat	myk: The real primary usage is for new NOT NULL columns with no DEFAULT.
	myk	mkanat: so init_value is only used to reset the value of the field for
existing records? after column creation it is no longer used, and the value in
the DEFAULT clause (if any) is used to set the value of the field for new records?
	mkanat	The real SQL restriction is that you can't set a column to be NOT NULL
that contains any NULLs.
	mkanat	myk: Exactly.
	myk	mkanat: then that's what the docs should say; otherwise people will be
confused about whether to use DEFAULT or init_value to specify the default value
for the column
	mkanat	myk: OK. Could you file a bug on that, and I'll modify them?
	myk	mkanat: yes

Updated

8 years ago
Assignee: mkanat → general
You need to log in before you can comment on or make changes to this bug.