add some sql

This commit is contained in:
2019-12-31 14:39:29 +11:00
parent e0a7bce9d7
commit 7b2e927e3f
+32 -4
View File
@@ -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: