mirror of
https://github.com/wahyd4/knowledge.git
synced 2026-08-09 05:06:28 +10:00
add some sql
This commit is contained in:
+32
-4
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user