Contents
About ................................................................................................................................................................................... 1
Chapter 1: Geng started with PostgreSQL .................................................................................................. 2
Secon 1.1: Installing PostgreSQL on Windows ........................................................................................................... 2
Secon 1.2: Install PostgreSQL from Source on Linux ............................................................................................... 3
Secon 1.3: Installaon on GNU+Linux ......................................................................................................................... 4
Secon 1.4: How to install PostgreSQL via MacPorts on OSX ................................................................................... 5
Secon 1.5: Install postgresql with brew on Mac ........................................................................................................ 7
Secon 1.6: Postgres.app for Mac OSX ........................................................................................................................ 7
Chapter 2: Data Types ............................................................................................................................................... 8
Secon 2.1: Numeric Types ........................................................................................................................................... 8
Secon 2.2: Date/ Time Types .................................................................................................................................... 8
Secon 2.3: Geometric Types ....................................................................................................................................... 9
Secon 2.4: Network Adress Types ............................................................................................................................. 9
Secon 2.5: Character Types ....................................................................................................................................... 9
Secon 2.6: Arrays ......................................................................................................................................................... 9
Chapter 3: Dates, Timestamps, and Intervals ............................................................................................. 11
Secon 3.1: SELECT the last day of month ............................................................................................................... 11
Secon 3.2: Cast a mestamp or interval to a string .............................................................................................. 11
Secon 3.3: Count the number of records per week ............................................................................................... 11
Chapter 4: Table Creaon ..................................................................................................................................... 12
Secon 4.1: Show table denion ............................................................................................................................... 12
Secon 4.2: Create table from select ........................................................................................................................ 12
Secon 4.3: Create unlogged table ........................................................................................................................... 12
Secon 4.4: Table creaon with Primary Key .......................................................................................................... 12
Secon 4.5: Create a table that references other table .......................................................................................... 13
Chapter 5: SELECT ...................................................................................................................................................... 14
Secon 5.1: SELECT using WHERE ............................................................................................................................. 14
Chapter 6: Find String Length / Character Length ................................................................................... 15
Secon 6.1: Example to get length of a character varying eld ............................................................................. 15
Chapter 7: COALESCE ............................................................................................................................................... 16
Secon 7.1: Single non null argument ........................................................................................................................ 16
Secon 7.2: Mulple non null arguments .................................................................................................................. 16
Secon 7.3: All null arguments ................................................................................................................................... 16
Chapter 8: INSERT ...................................................................................................................................................... 17
Secon 8.1: Insert data using COPY ........................................................................................................................... 17
Secon 8.2: Inserng mulple rows ........................................................................................................................... 18
Secon 8.3: INSERT data and RETURING values ..................................................................................................... 18
Secon 8.4: Basic INSERT ........................................................................................................................................... 18
Secon 8.5: Insert from select .................................................................................................................................... 18
Secon 8.6: UPSERT - INSERT ... ON CONFLICT DO UPDATE.. ................................................................................ 19
Secon 8.7: SELECT data into le .............................................................................................................................. 19
评论