CHAPTER 28 FROM DATABASES TO DATATYPES (Web server info) SERIAL

CHAPTER 28 FROM DATABASES TO DATATYPES SERIAL The SERIAL type is not a true type, but is actually a notational convenience for setting up autoincrementing identifier columns. In PostgreSQL 8.0, specifying CREATE TABLE tblname ( colname SERIAL ); is the equivalent of: CREATE TABLE tblname ( colname INTEGER DEFAULT nextval(’tblname_colname_seq’) NOT NULL ); Both cases create an INTEGER column and arrange for its value to be assigned from a sequence generator, with the difference being that the SERIAL syntax also attempts to create the sequence automatically upon table creation, rather than having to create the sequence manually. Conversely, sequences created via the SERIAL syntax will also be dropped automatically if the column or table is dropped. Normally, when creating a SERIAL column, you also want to specify a UNIQUEor PRIMARYKEY constraint to prevent duplicate values from being inserted by accident, but this is not automatic. Primary keys are explained a bit later, in the PRIMARY KEY section. Since the SERIAL type is implemented using the INTEGER type, it can only hold up to 2,147,483,647 values. While this is usually enough for most applications, if you expect that you will need more identifiers, you can use the type BIGSERIAL. BIGSERIAL behaves in all the same respects as SERIAL, except that it uses the BIGINT type for its underpinnings, and thus can support a range up to 9,223,372,036,854,775,807 values. String Datatypes PostgreSQL s string types are greatly simplified compared to many other database systems, but they are still the basis for storing string data. This section introduces the string types. CHAR[(length)] The CHAR datatype offers PostgreSQL s fixed-length string representation. If a string longer than length is inserted, it will produce an error, unless the characters are all spaces, in which case the string will be truncated to length. (This exception, while odd to some, is required by the SQL standard.) If an inserted string does not occupy length spaces, the remaining space will be padded by blank spaces. A CHAR declaration without a length is equivalent to CHAR(1). CHAR is equivalent to the SQL standard CHARACTER(n), and both names can be used interchangeably. Note There is also a datatype “char” (note the quotes and lowercase) that is different from CHAR or CHAR(1) in that it uses only 1 byte for storage. It is used internally within the system tables and is not intended for general use. It is mentioned here because some applications and developers may accidentally quote the CHAR attribute, which can lead to unexpected behavior.
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Leave a Reply