SlideShare a Scribd company logo
DATA TYPES
Masters Academy, 2018
- Types
- Structures
Types
- Number
- Integer
- Float
- Number
- String
- Char
- Character varying
- Text
- Boolean
Types integer
Tiny integer tinyint, byte 0..255 8 bit
Small Integer smallint -32768
+32767
16 bit
integer smallint -2147483648
+2147483647
32 bit
Big integer bigint -9223372036854775808
+9223372036854775807
64 bit
Types float
Float float 1.175494351 E -38
3.402823466 E +38
6 - 7 32 bit
Double double 2.2250738585072014 E -308
1.7976931348623158 E +308
15 - 16 64 bit
Types string
Char a, b, 1, 3, -
, +, ], ...
Varchar abc, bcd,
123, ...
Text abc, bcd,
123, ...
} 4 Gb
Types Boolean
TRUE, FALSE
0 1
YES NO
PRESENT ABSENT
}1 Bit
Structures
- Variable
- Pointer
- Array
- List
- Tree
- Graph
- Hash
- Set
- JSON
Structures Variable
a = 1
a1 = 5
AA = ‘ab’
Structures Variable
- Starts with a-zA-Z
- Contains only a-zA-Z0-9_
- No spaces or special characters
- Cannot be same as keyword
Structures Pointer
pointer
2045
variable
123.5
2045 1246
Structures Array
[1, 2, 120, 150, 11, 13]
[‘ab’, ‘cd’, ‘ef’]
[1, ‘a’, 2, ‘bca’, 123, ‘z’]
Structures Array
1 ab 12 31 cde 131 frt
0 1 2 3 4 5 6
Structures Array
1 ab 12 31 cde 131 frt
-7 -6 -5 -4 -3 -2 -1
Structures Array
arr = [1, ‘ab’, 12, 31, ‘cde’, 131, ‘frt’]
arr[0] => 1
arr[2] => ‘ab’
arr[-1] => ‘frt’
arr[-3] => ‘cde’
Structures Array String
str = ‘we are masters’
W E A R E M A S T E R S
Structures Array String
str = ‘we are masters’
W E A R E M A S T E R S
W E A R E M A S T E R S
Structures Array String
str1 = ‘we’ str2 = ‘are’ str3 = ‘masters’
str1 + str2 + str3 = ‘wearemasters’
str1 - str2 = ‘w’
str1 & str2 = ‘e’
Structures Array
str1 = [‘w’, ’e’] str2 = [‘a’, ’r’, ’e’] str3 = [‘m’,’a’,’s’,’t’,’e’,’r’,’s’]
str1 + str2 + str3 = [‘w’,’e’,’a’,’r’,’e’,’m’,’a’,’s’,’t’,’e’,’r’,’s’]
str1 - str2 = [‘w’]
str1 & str2 = [‘e’]
72 5
Structures List
pointer
pointer
head tail
Structures Tree
Structures Tree
1
2
4 5
3
6 7
Structures Tree
1
2
4 5
3
6 7
true false
Structures Tree
1
2
4 5
3
6 7
true false
Structures Graph
1
2
4 5
3
6 7
Structures Graph
1
2
4 5
3
6 7
Structures Graph
1
2
4 5
3
6 7
Structures Graph
1
2
4 5
3
6 7
Structures Graph
1
2
4 5
3
6 7
Structures Graph
1
2
4 5
3
6 7
Structures Graph
1
2
4 5
3
6 7
Structures Graph
1
2
4 5
3
6 7
1 10
3
4
Structures Hash (Associated Array)
Structures Hash
h = { ‘a’ => 1, ‘b’ => 2 }
h = { ‘a’: 1, ‘b’: 2 }
h = { a: 1, b: 2 }
h[‘a’] => 1
h[‘a’] => 1
h[‘a’] => 1 h[:a] => 1
Structures Hash
h = { a: 1, b: 2 }
value = hash(key)
key value
1 = hash(‘a’)
2 = hash(‘b’)
Structures Hash
h = { a: 1, b: 2 }
h = { a: ‘1’, b: 2 }
h = { a: ‘1’, b: [2] }
h = { a: ‘1’, b: { c: 2 } }
Structures Set
set = { 1, 2, 3, 4, 5, 6, 6, 1 }
set = { 1, ‘2’, 3, ‘4’, [5], 6, 6, 1 }
set = { {1} ,{’2’} ,{3}, {‘4’}, { [5] }, { 6, 6, 1 } }
set = { {1} ,’2’ ,{3}, {‘4’}, [5], { 6, 6, 1 } }
Structures Set
set1 = { 1, 2, 3 } set2 = { 2, 3,
4, 5 }
set1  set2 => { 1 }
set1 | set2 => { 1, 2, 3, 4, 5 }
set1 △ set2 => { 1, 4, 5 }
Structures JSON
{
“a”: 1,
“b”: “2”,
“c”: [3],
“d”: [“4”],
“e”: { “f”: 5, “g”: [“6”] }
}
Structures JSON
{
“a”: 1,
“b”: “2”,
“c”: [3],
“d”: [“4”],
“e”: { “f”: 5, “g”: [“6”] }
}
“{“a”:1,“b”:“2”,“c”:[3],“d”:[“4”],“e”:{“f”:5,“g”:[“6”]}}”
Typing
integer →
float
float →
integer
float →
string
string →
Typing
- Dynamic
- Static
- Strong
- Weak
Typing
10 000 users
Typing
10 000 users
longest name ~ up to 50 symbols
Typing
10 000 users
longest name ~ up to 50 symbols
longest uk name ~ up to 15 symbols
Typing
one name = 50 symbols = 50 bytes
one name = 50 symbols = 52 bytes
x 10 000 users = 520 000 bytes ~= 51 kB
Typing
one name = 15 symbols = 15 bytes
one name = 15 symbols = 16 bytes
x 10 000 users = 160 000 bytes ~= 15 kB
Typing
Q & A

More Related Content

Data Types