Why the length of the int4 type of postgresql can reach 10 bits

two questions:

  1. Why the length of the int4 type of postgresql can reach 10 bits, but it is set to 32 bits in the attribute
  2. The int4 type length of
  3. postgresql is set to 32 bits by default, so why can"t it be modified? it is still 32 bits after modification

screenshot:

this is the data attribute of int4 in the table structure

1132

10

11


use NaviCat to connect PG? I never thought it could be like this.

back to the point. It seems that some of the displays on the GUI tool have misunderstood the subject. Let's briefly explain:

The int4 type in

PG corresponds to the INTEGER type in the SQL standard, and PG implements the source integer type, which is with a fixed length of 4 bytes (= 32-bit bit). The corresponding range of decimal values is -"21474836478 ~" 2147483647 "

therefore, the operation error shown in the main screenshot is as follows:

    In the first and second picture of
  1. , the subject is trying to modify the length of a column of type INTGEGER : as mentioned above, INTEGER is a 32-bit binary of fixed length , so this operation must be futile.

    but GUI also has something to complain about. Its concept of "length" seems to be ambiguous

    .
  2. In the third and fourth picture of
  3. , the subject tries to insert a value in the range of INTEGER and a value outside the range of INTEGER into fields of type INTEGER, respectively. So the second attempt is a failure (the second 12345678901 exceeds the INTEGER maximum 2147483647 bits )

    in addition, from the description of the subject, the subject does not seem to know the difference between binary and decimal digits. The subject has been emphasizing the need to insert a 11-bit decimal number . Maybe the subject mistakenly thinks that it should be able to insert when it shows that the INTEGER type has "32 bits" in GUI. But the 32 bits here are actually binary bits ( this is also the slot point of the GUI I mentioned above: when it shows the NUMERIC type, I'm afraid the length will become the decimal length again )

finally, if the question mainly inserts 11-digit decimal numbers, you can consider changing the type of the column to BIGINT ( int8 ) or directly using the NUMERIC type

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b330aa-2be48.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b330aa-2be48.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?