tags:

views:

37

answers:

1

Just doing a site which requires multiple items to be reordered by AJAX.

When I create a given object in the database, I want to set the position column to the value of the rows' primary key upon creation.

How would I do this please?

A: 

A citation from MySQL documentation:

The DEFAULT clause specifies a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP column. See Section 10.3.1.1, “TIMESTAMP Properties”.

You can though obtain the id value on selection instead:

SELECT id, COALESCE(position, id) as position ...
newtover
Thankyou, ill just do it with code and manulaly update after creation
mfisher86