Postgresql 7.3.2 User's Guide
Total Page:16
File Type:pdf, Size:1020Kb
PostgreSQL 7.3.2 User’s Guide The PostgreSQL Global Development Group PostgreSQL 7.3.2 User’s Guide by The PostgreSQL Global Development Group Copyright © 1996-2002 by The PostgreSQL Global Development Group Legal Notice PostgreSQL is Copyright © 1996-2002 by the PostgreSQL Global Development Group and is distributed under the terms of the license of the University of California below. Postgres95 is Copyright © 1994-5 by the Regents of the University of California. Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PRO- VIDED HEREUNDER IS ON AN “AS-IS” BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. Table of Contents Preface ..................................................................................................................................................i 1. What is PostgreSQL? ...............................................................................................................i 2. A Short History of PostgreSQL ...............................................................................................i 2.1. The Berkeley POSTGRES Project .............................................................................ii 2.2. Postgres95...................................................................................................................ii 2.3. PostgreSQL................................................................................................................iii 3. What’s In This Book ..............................................................................................................iii 4. Overview of Documentation Resources.................................................................................iv 5. Terminology and Notation ......................................................................................................v 6. Bug Reporting Guidelines.......................................................................................................v 6.1. Identifying Bugs ........................................................................................................vi 6.2. What to report............................................................................................................vi 6.3. Where to report bugs ...............................................................................................viii 1. SQL Syntax......................................................................................................................................1 1.1. Lexical Structure ..................................................................................................................1 1.1.1. Identifiers and Key Words .......................................................................................1 1.1.2. Constants .................................................................................................................2 1.1.2.1. String Constants..........................................................................................2 1.1.2.2. Bit-String Constants....................................................................................3 1.1.2.3. Numeric Constants......................................................................................3 1.1.2.4. Constants of Other Types............................................................................4 1.1.2.5. Array constants ...........................................................................................4 1.1.3. Operators .................................................................................................................5 1.1.4. Special Characters ...................................................................................................5 1.1.5. Comments................................................................................................................6 1.1.6. Lexical Precedence..................................................................................................6 1.2. Value Expressions ................................................................................................................7 1.2.1. Column References .................................................................................................8 1.2.2. Positional Parameters ..............................................................................................8 1.2.3. Operator Invocations ...............................................................................................9 1.2.4. Function Calls..........................................................................................................9 1.2.5. Aggregate Expressions ............................................................................................9 1.2.6. Type Casts..............................................................................................................10 1.2.7. Scalar Subqueries ..................................................................................................10 1.2.8. Expression Evaluation ...........................................................................................11 2. Data Definition ..............................................................................................................................12 2.1. Table Basics .......................................................................................................................12 2.2. System Columns ................................................................................................................13 2.3. Default Values ....................................................................................................................14 2.4. Constraints .........................................................................................................................14 2.4.1. Check Constraints..................................................................................................15 2.4.2. Not-Null Constraints .............................................................................................16 2.4.3. Unique Constraints ................................................................................................17 2.4.4. Primary Keys .........................................................................................................18 2.4.5. Foreign Keys..........................................................................................................18 2.5. Inheritance..........................................................................................................................21 2.6. Modifying Tables ...............................................................................................................23 2.6.1. Adding a Column ..................................................................................................23 iii 2.6.2. Removing a Column..............................................................................................23 2.6.3. Adding a Constraint...............................................................................................23 2.6.4. Removing a Constraint ..........................................................................................24 2.6.5. Changing the Default.............................................................................................24 2.6.6. Renaming a Column..............................................................................................24 2.6.7. Renaming a Table ..................................................................................................24 2.7. Privileges............................................................................................................................25 2.8. Schemas .............................................................................................................................25 2.8.1. Creating a Schema.................................................................................................26 2.8.2. The Public Schema................................................................................................27 2.8.3. The Schema Search Path .......................................................................................27 2.8.4. Schemas and Privileges .........................................................................................28 2.8.5. The System Catalog Schema.................................................................................28 2.8.6. Usage Patterns .......................................................................................................29 2.8.7. Portability ..............................................................................................................29 2.9. Other Database Objects......................................................................................................30