Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:02,048 --> 00:00:04,096
Next we will look at the trim functions
1
2
00:00:05,376 --> 00:00:09,984
In postgres there are three type of trim functions one is normal trim
2
3
00:00:10,496 --> 00:00:13,568
Other is a rtrim and there is ltrim
3
4
00:00:14,592 --> 00:00:18,176
Trim can be used to replace all specified characters
4
5
00:00:18,432 --> 00:00:21,248
Either from the beginning or at the end or both
5
6
00:00:22,272 --> 00:00:28,160
RTrim will remove only characters from the right hand side of the string Ltrim remove only from the left hand side
6
7
00:00:28,416 --> 00:00:31,232
So trim can do work of both Rtrim and Ltrim
7
8
00:00:31,744 --> 00:00:32,768
Let us see how
8
9
00:00:33,280 --> 00:00:34,816
in the syntax you can see
9
10
00:00:35,072 --> 00:00:36,352
When you write trim
10
11
00:00:36,864 --> 00:00:37,632
In the brackets
11
12
00:00:37,888 --> 00:00:42,752
You have the option of mentioning leading trailing or both. By default it will be both
12
13
00:00:43,520 --> 00:00:45,056
If you mention leading
13
14
00:00:45,312 --> 00:00:47,104
It will function is Ltrim
14
15
00:00:47,616 --> 00:00:50,688
That is it will remove characters from the left side of the string
15
16
00:00:51,456 --> 00:00:54,272
If you mention trailing it will behave as rtrim
16
17
00:00:54,528 --> 00:00:56,832
That is it will remove from the right hand side of the string
17
18
00:00:57,856 --> 00:01:00,160
After mentioning leading trailing both
18
19
00:01:00,672 --> 00:01:01,952
You have to mention the
19
20
00:01:02,720 --> 00:01:03,744
Trim character
20
21
00:01:04,256 --> 00:01:09,376
The character that you want to trim if you do not mention any character it will remove only spaces
21
22
00:01:09,632 --> 00:01:12,192
If you know that it is a particular character
22
23
00:01:12,448 --> 00:01:18,080
So for example if you have additional commas or any other particular character you can mention that character also
23
24
00:01:18,848 --> 00:01:20,384
By default it will be a space
24
25
00:01:21,408 --> 00:01:23,200
and then you mention the string
25
26
00:01:24,736 --> 00:01:27,552
The syntax for Rtrim and Ltrim are a little different
26
27
00:01:27,808 --> 00:01:31,648
You first mention the string and then you mention the trim character
27
28
00:01:31,904 --> 00:01:32,672
so the
28
29
00:01:32,928 --> 00:01:34,720
String comes first you then
29
30
00:01:34,976 --> 00:01:37,792
Mention the character that you want to trim from that string
30
31
00:01:38,304 --> 00:01:40,608
So trim will mainly be used to clean your data
31
32
00:01:40,864 --> 00:01:42,400
For example if your data
32
33
00:01:42,656 --> 00:01:45,472
Has been created by input from customers
33
34
00:01:45,728 --> 00:01:50,080
Then it tends to have additional spaces in the beginning in the end
34
35
00:01:50,336 --> 00:01:52,896
In such cases where your data is not that clean
35
36
00:01:53,408 --> 00:01:54,944
You can use trim function
36
37
00:01:55,200 --> 00:02:00,064
If you do not use trim function due to these additional spaces you will not be able to match the strings
37
38
00:02:00,576 --> 00:02:03,904
So matching will also be a difficulty with unclean data
38
39
00:02:04,672 --> 00:02:05,952
So trim will help you
39
40
00:02:06,464 --> 00:02:12,608
Clean the data and if you further want to match the strings that will also be easier after doing trim
40
41
00:02:12,864 --> 00:02:13,376
On the
41
42
00:02:13,632 --> 00:02:14,400
column name
42
43
00:02:16,192 --> 00:02:17,728
If you look at the examples
43
44
00:02:19,008 --> 00:02:21,312
If I write select trim leading
44
45
00:02:22,080 --> 00:02:23,616
This is the character space
45
46
00:02:24,384 --> 00:02:24,896
From
46
47
00:02:25,664 --> 00:02:31,552
This string this is a string Start-Tech Academy it has some spaces in the front some in the back
47
48
00:02:32,320 --> 00:02:37,184
If you mention leading, it will only remove the leading spaces which are the
48
49
00:02:37,440 --> 00:02:38,976
The spaces which are coming
49
50
00:02:39,232 --> 00:02:40,512
Before the string
50
51
00:02:41,024 --> 00:02:43,328
So it will remove only these
51
52
00:02:43,584 --> 00:02:44,352
Spaces
52
53
00:02:45,888 --> 00:02:49,984
If you mention trailing it will only remove these spaces not these spaces
53
54
00:02:50,752 --> 00:02:52,032
If you mention both
54
55
00:02:52,288 --> 00:02:54,080
It will remove spaces from both the sides
55
56
00:02:54,848 --> 00:02:56,384
If you do not mention
56
57
00:02:56,640 --> 00:02:57,408
Any of these
57
58
00:02:57,920 --> 00:02:59,456
By default it will remove
58
59
00:02:59,712 --> 00:03:01,248
From both the sides
59
60
00:03:01,504 --> 00:03:04,064
If you even do not mention this character
60
61
00:03:04,832 --> 00:03:08,416
It will still remove the spaces because default character is space
61
62
00:03:08,672 --> 00:03:12,000
If it had been any other character you need to mention
62
63
00:03:12,256 --> 00:03:13,280
that particular character
63
64
00:03:15,328 --> 00:03:16,608
For Rtrim
64
65
00:03:17,632 --> 00:03:20,704
Again when we write this it will remove spaces from the end
65
66
00:03:21,472 --> 00:03:23,264
Ltrim will remove spaces from
66
67
00:03:23,520 --> 00:03:24,288
Left end
67
68
00:03:24,544 --> 00:03:26,848
So let us go and write all of these
68
69
00:03:31,200 --> 00:03:33,760
So we will first trim
69
70
00:03:35,040 --> 00:03:38,112
The leading so it will be leading
70
71
00:03:39,392 --> 00:03:40,416
then we'll mention the
71
72
00:03:40,672 --> 00:03:43,232
Space character within single quote
72
73
00:03:47,584 --> 00:03:50,656
Then we will mention from
73
74
00:03:51,168 --> 00:03:52,704
And then we will give the string
74
75
00:03:52,960 --> 00:03:59,104
This can be a string or you can mention a column name also so this will remove
75
76
00:03:59,360 --> 00:04:00,640
All the
76
77
00:04:00,896 --> 00:04:03,712
Leading spaces from that column values
77
78
00:04:03,968 --> 00:04:08,320
So let us run this query and see
78
79
00:04:11,136 --> 00:04:11,904
So if you
79
80
00:04:12,160 --> 00:04:13,184
expand this
80
81
00:04:14,208 --> 00:04:15,232
You can see
81
82
00:04:15,488 --> 00:04:21,631
There are extra spaces after Academy but the spaces in front of start have been removed
82
83
00:04:22,655 --> 00:04:24,959
If you change the leading
83
84
00:04:25,983 --> 00:04:26,495
to
84
85
00:04:26,751 --> 00:04:29,055
Trailing
85
86
00:04:29,311 --> 00:04:32,383
Leading to trailing
86
87
00:04:32,639 --> 00:04:34,175
and you run this
87
88
00:04:37,759 --> 00:04:40,063
the spaces in the front are still there
88
89
00:04:42,367 --> 00:04:42,879
But
89
90
00:04:43,135 --> 00:04:45,439
Spaces in the end have been removed
90
91
00:04:49,023 --> 00:04:50,559
If you write both
91
92
00:04:53,631 --> 00:04:58,751
Spaces from both the sides will be removed
92
93
00:05:01,311 --> 00:05:03,103
Let's run this
93
94
00:05:03,359 --> 00:05:05,919
Double click you can see
94
95
00:05:06,175 --> 00:05:07,967
Spaces from both the sides are removed
95
96
00:05:08,223 --> 00:05:12,831
If you remove both also and the special character also
96
97
00:05:13,343 --> 00:05:14,623
It will still Run
97
98
00:05:15,135 --> 00:05:20,255
With the default values of both and space and
98
99
00:05:21,535 --> 00:05:23,583
it'll still give us the same result
99
100
00:05:29,215 --> 00:05:29,983
So you can see
100
101
00:05:30,239 --> 00:05:33,567
we still have the same result when no extra spaces on
101
102
00:05:33,823 --> 00:05:34,335
Either sides
102
103
00:05:35,359 --> 00:05:37,151
Next we'll look at Rtrim
103
104
00:05:38,943 --> 00:05:39,711
Select
104
105
00:05:41,759 --> 00:05:42,783
Rtrim
105
106
00:05:44,319 --> 00:05:45,599
First mention the
106
107
00:05:45,855 --> 00:05:49,695
String which is Start-Tech Academy with spaces on both the sides
107
108
00:05:56,863 --> 00:05:59,167
Then after comma mention the
108
109
00:06:00,447 --> 00:06:02,239
Character to be
109
110
00:06:02,495 --> 00:06:06,079
trimmed. let's run this
110
111
00:06:06,591 --> 00:06:12,735
So you can see that only the right spaces have been removed, the left spaces are
111
112
00:06:12,991 --> 00:06:13,503
Still there
112
113
00:06:14,015 --> 00:06:17,855
If you write Ltrim on this same
113
114
00:06:18,111 --> 00:06:18,623
string
114
115
00:06:19,903 --> 00:06:21,951
Just copy paste it
115
116
00:06:22,207 --> 00:06:25,279
use Ltrim
116
117
00:06:25,535 --> 00:06:29,119
You'll notice that the spaces in front will be removed
117
118
00:06:33,215 --> 00:06:34,751
Spaces in the end are still there
118
119
00:06:35,775 --> 00:06:39,103
So this is Trim, Ltrim and Rtrim for you
119
120
00:06:39,359 --> 00:06:45,503
Just to repeat that trim is a very important function to clean your data and to match those textual
120
121
00:06:45,759 --> 00:06:46,271
columns
121
122
00:06:46,527 --> 00:06:50,111
So whenever you are joining or matching text using the where clause
122
123
00:06:50,367 --> 00:06:51,391
Do remember to use
123
124
00:06:51,647 --> 00:06:52,159
Trim or the upper lower functions whenever you do not have the standardized data
9854
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.