歡迎!

在 PostgreSQL 操作資料的函式

Brian Piccolo

Sr. Director, Digital Strategy

Sakila 資料庫

  • 高度正規化
  • 具代表性的資料型別
  • 自訂函式
在 PostgreSQL 操作資料的函式

主題

  • PostgreSQL 常見資料型別
  • 日期與時間的函式與運算子
  • 文字解析與處理
  • 全文檢索與 PostgreSQL 擴充套件
在 PostgreSQL 操作資料的函式

常見資料型別

  • 文字型別
    • CHARVARCHARTEXT
  • 數值型別
    • INTDECIMAL
  • 日期/時間型別
    • DATETIMETIMESTAMPINTERVAL
  • 陣列
在 PostgreSQL 操作資料的函式

文字型別

SELECT title 
FROM film
LIMIT 5
+-------------------+
| title             |
|-------------------|
| ACADEMY DINOSAUR  |
| ACE GOLDFINGER    |
| ADAPTATION HOLES  |
| AFFAIR PREJUDICE  |
| AFRICAN EGG       |
+-------------------+
SELECT description 
FROM film
LIMIT 2
+-----------------------------------------+
| description                             |
|-----------------------------------------|
| A Epic Drama of a Feminist And a Mad    |     
|  Scientist who must Battle a Teacher in |
|  The Canadian Rockies.                  |
| A Astounding Epistle of a Database      |
|  Administrator And a Explorer who       |
|  must Find a Car in Ancient China       |
+-----------------------------------------+
在 PostgreSQL 操作資料的函式

數值型別

SELECT 
    payment_id 
FROM payment 
LIMIT 5
+-------------+
| payment_id  |
|-------------|
| 1           |
| 2           |
| 3           |
| 4           |
| 5           |
+-------------+
SELECT 
    amount
FROM payment 
LIMIT 5
+--------+
| amount |
|--------|
| 2.99   |
| 0.99   |
| 5.99   |
| 0.99   |
| 9.99   |
+--------+
在 PostgreSQL 操作資料的函式

從既有資料表判斷型別

SELECT 
    title, 
    description, 
    special_features 
FROM FILM 
LIMIT 5
+---------------+------------------+------------------------------+
| title         |  description     | special_features             |
|---------------|------------------|------------------------------|
| ACADEMY D...  | A Epic...        | {Deleted Scenes,Behi...}     |
| ACE GOLD...   | A Astound..      | {Trailers,Deleted Scenes}    |
| AFFAIR PR...  | A Fanciful,..    | {Commentaries,Behind the...} |
+---------------+------------------+------------------------------+
在 PostgreSQL 操作資料的函式

從既有資料表判斷型別

SELECT
    column_name, 
    data_type
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE column_name in ('title','description','special_features')
  AND table_name ='film';
+------------------+-------------------+
| column_name      | data_type         |
|------------------|-------------------|
| title            | character varying |
| description      | text              |
| special_features | ARRAY             |
+------------------+-------------------+
在 PostgreSQL 操作資料的函式

一起來練習吧!

在 PostgreSQL 操作資料的函式

Preparing Video For Download...