From 7b2e927e3fc68f2037a6ff5e63c7cfc13a9d5a7e Mon Sep 17 00:00:00 2001 From: Junwei Zhao Date: Tue, 31 Dec 2019 14:39:29 +1100 Subject: [PATCH] add some sql --- categories/database.md | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/categories/database.md b/categories/database.md index bffd8f6..0deea1b 100644 --- a/categories/database.md +++ b/categories/database.md @@ -18,11 +18,14 @@ - Cassendra # SQL -- Index + +## Index - Index is unique but not mandatory -- join -- MYSQL - - tips +## join + +## MYSQL + +### Tips - datetime - 8 bytes `1000-01-01 00:00:00 ~ 9999-12-31 23:59:59` @@ -32,6 +35,31 @@ - will impacted by time zone - index by timestamp will be faster than datetime due to 4 bytes. +## Postgres + +### Create a table + +```sql +CREATE TABLE pm25 +( + id SERIAL, -- id with auto increment + time TIMESTAMP not NULL, + pm25 integer DEFAULT 0, + concentration integer DEFAULT 0, + city VARCHAR not NULL +); + +``` +### Import data from CSV +```sql + COPY persons(first_name,last_name,dob,email) + FROM 'C:\tmp\persons.csv' DELIMITER ',' CSV HEADER; +``` +### Import data with SQL +```bash +psql -U postgres -W -p 5432 -d somename -h 127.0.0.1 -f ~/somefile.sql +``` + ## Postgres trigger example Giving we have a table called users, and the columns are: