PostgreSQL

Скачать в pdf «PostgreSQL»


This chapter has shown these commands in their simplest forms; real-world queries are much more complex. The next chapters will show how these simple commands can be used to handle some very complicated tasks.

Chapter 4

Customizing Queries


This chapter will illustrate additional capabilities of the basic SQL commands.

4.1 Data Types


Table
4.1 lists the most common column data types. Figure 4.1 shows queries using these types. Notice that numbers do not require quotes, but character strings, dates, and times do require them.


The final SELECT uses psql’s x display mode.1Without x, the SELECT would have displayed too much information to fit on one line. The fields would have wrapped around the edge of the display, making it difficult to read. The columns would still line up, but there would be other data in the way. Of course, another solution to field wrapping is to select fewer columns. Remember, you can select any columns from the table in any order.


Section 9.2 covers column types in more detail.


1See Section 16.1 for a full list of the psql backslash commands.


Category


Type


Description


character string


CHARI length) VARCHARl length)


blank-padded string, fixed storage length variable storage length


number


INTEGER


integer, +1-2 billion range


FLOAT


NUMERIClprecision, decimal)


floating point number, 15-digit precision number with user-defined precision and decimal location


date/time


DATE


date


TIME


time


TIMESTAMP


date and time

Table 4.1: Common data types

Скачать в pdf «PostgreSQL»