← Back to team overview

maria-discuss team mailing list archive

Re: Doubt about 'atomic' insert

 

Hi Sergei!

2014-12-13 21:06 GMT-02:00 Sergei Golubchik <serg@xxxxxxxxxxx>:
>
> Depends on how many rows the table errorsX has.
>
> If it has only one row, than this INSERT ... SELECT will insert a one
> row with a different id. No error.
>
> If it has more than one row, this INSERT ... SELECT will try to insert
> more than one row, all with the same id value - there will be a
> duplicate key error.
>
> Regards,
> Sergei
>


well, let me reformulate the query...
INSERT INTO errorsX (id) SELECT IFNULL(MAX(id),0)+1 FROM errorsX GROUP BY
NULL;

considering only a single row result with always >0 not null values

References