Skip to content

Commit 5980498

Browse files
committed
Datatypes
1 parent b86b1d9 commit 5980498

File tree

1 file changed

+110
-1
lines changed

1 file changed

+110
-1
lines changed

README.md

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ completion date: 2021-10-16
7272
+ [LEAST](#least)
7373
+ [CASE](#case)
7474

75+
---
76+
[10. PostgreSQL](#10-postgresql)
77+
+ [Installation](#installation)
78+
7579
---
7680
###### <div style="text-align:right">[table of contents](#table-of-contents)</div>
7781
## 1. Basics
@@ -978,6 +982,7 @@ SELECT
978982
)
979983
```
980984
---
985+
###### <div style="text-align:right">[table of contents](#table-of-contents)</div>
981986

982987
## 8. Destinct
983988
SQL keyword: DESTINCT
@@ -1001,6 +1006,9 @@ FROM products;
10011006
```
10021007

10031008
---
1009+
1010+
###### <div style="text-align:right">[table of contents](#table-of-contents)</div>
1011+
10041012
## 9. Utility Operators, Keywords, and Functions
10051013

10061014
#### GREATEST
@@ -1037,4 +1045,105 @@ SELECT
10371045
ELSE 'cheap'
10381046
END
10391047
FROM products;
1040-
```
1048+
```
1049+
1050+
---
1051+
---
1052+
###### <div style="text-align:right">[table of contents](#table-of-contents)</div>
1053+
1054+
## 10. PostgreSQL
1055+
* Installing postgreSQL installs pgadmin.
1056+
* Pgadmin is a web-based tool to manage and inspect a postgres database.
1057+
* One postgres server can have multiple databases.
1058+
* One app usually associated with one database.
1059+
* use Query Editor to test SQL
1060+
1061+
#### Installation
1062+
1063+
* installation https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
1064+
* during install -> uncheck stack builder
1065+
* password is password for local machine
1066+
* run pgAdmin 4 -> password is to access pgadmin
1067+
* clicking on servers -> requested password is password for localmachine.
1068+
1069+
### Data types Categories
1070+
#### most used:
1071+
##### Numbers
1072+
* Numbers without any decimal points: (smallint, integer, bigint)
1073+
* No decimal point, auto increment: (smallserial, serial, bigserial)
1074+
* Number with decimal points: (decimal, numeric, real, double precision, float)
1075+
1076+
(RULES):
1077+
* SERIAL - id column on any table
1078+
* INTEGER - store number without decimal
1079+
* NUMERIC - store number with decimal - data needs to be accurate (bank balance, scientific calculations)
1080+
* DOUBLE PRECISION - store number with decimal - data doesnt need to be accurate (floating point math - eg. calculations result in something like 1.001358e-05)
1081+
1082+
##### Character
1083+
No performance benefits between types
1084+
1085+
* CHAR(4) - store some characters, length will always be 4 even if postgres has to add spaces
1086+
* VARCHAR(40) - store a string up to 40 chars, automatically remove extra chars
1087+
* VARCHAR - store any length of string
1088+
* TEXT - Store any lenght of string
1089+
1090+
##### Boolean
1091+
* TRUE ('true', 'yes', 'on', 1, 't', 'y')
1092+
* FALSE ('false', 'no', 'off', 0, 'f', 'n')
1093+
* NULL (null)
1094+
1095+
##### Date
1096+
Can provide string in almost any format and postgres will do conversion
1097+
can specify something to be date by explicitly giving a data type with '::DATE'
1098+
1099+
```SQL
1100+
SELECT('NOV 20 1980'::DATE);
1101+
```
1102+
* 1980-11-20 -> 1980-11-20
1103+
* NOV-20-1980 -> 1980-11-20
1104+
* 20-Nov-1980 -> 1980-11-20
1105+
* 1980-November-20 -> 1980-11-20
1106+
* November 20, 1980 -> 1980-11-20
1107+
1108+
##### Time
1109+
1110+
* TIME or TIME WITHOUT TIME ZONE
1111+
* TIME WITH TIME ZONE (converts to UCT time)
1112+
* TIMESTAMP WITH TIME ZONE
1113+
1114+
```SQL
1115+
SELECT('01:23 AM'::TIME)
1116+
--13:23:00
1117+
1118+
SELECT('01:23 AM EST'::TIME WITH TIME ZONE)
1119+
--converted to 01:23-05:00 (the -05 means 5 hours behind UCT time)
1120+
1121+
SELECT('Nov-20-1980 05:23PM PST'::TIMESTAMP WITH TIME ZONE)
1122+
--converted to 1980-11-20 02:23:00-07 (date, time, UCT offset)
1123+
1124+
```
1125+
1126+
##### Interval
1127+
Can do math calculations on intervals.
1128+
Can mix INTERVAL with other TIME types.
1129+
Think of interval as a duration of time
1130+
* 1 day
1131+
* 1 D
1132+
* 1 D 1 M 1 S
1133+
1134+
1135+
```SQL
1136+
SELECT ('1 D 20 H 30 M 45 S'::INTERVAL) - ('1 D'::INTERVAL)
1137+
--result is 20:30:45
1138+
```
1139+
1140+
1141+
#### other:
1142+
* Currency
1143+
* arrays
1144+
* geometric
1145+
* range
1146+
* xml
1147+
* binary
1148+
* json
1149+
* UUID

0 commit comments

Comments
 (0)