Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - The difference between MySQL and PostgreSQL is increasing.
The difference between MySQL and PostgreSQL is increasing.
Conclusion:

1, mysql adds the AUTO_INCREMENT attribute in the field to realize self-increment, and pg uses the serial number type, which is actually not the real type. When a field is declared as a serial number type, it actually creates a sequence.

2.mysql inserts the values of fields, and pg changes the values of fields and sequences when inserting, but they are equal when inserting by default.

Therefore, if no value is assigned to this field during insertion, the next value or the next value of the corresponding sequence will be obtained by default.

However, after inserting an assignment in this field, it is different. When a pg assignment is inserted, the value of the field changes, but the value of the sequence does not. Therefore, when the assignment is inserted again by default, the next value of the corresponding sequence is still obtained in order.

3. After deletion, the insertion of mysql and pg is the same, except that truncate operation clears the table data on pg, but does not clear the corresponding sequence. So after executing truncate, inserting it again will get the next value of the corresponding sequence, starting from 1 on mysql.

4. It can't be inserted after reaching the specified maximum value, so it can't be recycled.

Remarks: The conclusion is based on the official account of [PostgreSQL Chinese Community] WeChat. This paper is an experimental step to record and verify the original conclusion, which is for learning only.