You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 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)
0 commit comments