WEBVTT

00:01.130 --> 00:04.910
To see these three character types in action.

00:04.910 --> 00:06.950
We will code some script here.

00:06.950 --> 00:13.550
So firstly, we will create the table and let's name it character data types, right?

00:13.550 --> 00:22.430
So create table and name it MyCar or yeah, character data types.

00:22.700 --> 00:23.810
Character.

00:24.590 --> 00:26.240
Data archives.

00:26.240 --> 00:28.100
And here we will add character.

00:28.100 --> 00:32.300
I will explain all of this with column Character is going to be ten.

00:33.860 --> 00:36.950
And the character after that is Comma.

00:37.220 --> 00:39.140
So our character.

00:40.970 --> 00:49.220
Var character column is going to be var character type, also ten and we will also add text.

00:49.220 --> 00:54.050
So text column column is going to be text.

00:54.500 --> 01:03.770
Just a text here and we will not define size because as we told, as I as you learned in previous lecture,

01:03.770 --> 01:11.330
that variable length column of text is has unlimited length.

01:11.330 --> 01:15.680
So that's why we didn't wrote anything onto this.

01:16.040 --> 01:26.260
And here we will use after that we will insert here, insert into character, oops, insert into car

01:27.080 --> 01:34.880
card data types, types and values insert into values of.

01:35.590 --> 01:37.630
A, B, C, for example.

01:37.660 --> 01:38.350
That's it.

01:38.380 --> 01:39.040
A, B, C.

01:39.400 --> 01:42.490
And after that, we will also enter ABC again.

01:42.520 --> 01:44.830
ABC again and ABC again.

01:47.440 --> 01:52.960
And that's actually due in part to my pen ink here.

01:53.930 --> 02:00.800
And here we will also after that we will add a comma, and after that we will also add the DFG.

02:01.790 --> 02:04.170
The a f g def.

02:06.680 --> 02:07.820
We'll copy that.

02:09.730 --> 02:10.870
Yes, again.

02:12.320 --> 02:12.680
That's it.

02:13.840 --> 02:14.350
That's it.

02:14.350 --> 02:14.680
Here.

02:14.680 --> 02:16.360
And we will copy.

02:16.630 --> 02:17.470
Copy.

02:18.620 --> 02:21.800
Uh, character data types.

02:23.680 --> 02:26.940
To and we will set the directory here.

02:26.950 --> 02:34.090
In this case, we can also set our directory into the desktop I guess.

02:34.090 --> 02:36.160
Yeah, we can use the desktop here.

02:36.160 --> 02:36.790
We will.

02:38.570 --> 02:43.490
Instead of this, we can also go to this and users Oxley.

02:45.190 --> 02:48.850
And after that, we'll add desktop here.

02:49.360 --> 02:49.930
That's it.

02:49.930 --> 02:55.060
And copy this to our desktop and after that.

02:55.060 --> 02:57.970
So of course we need to write this in quotes.

02:58.920 --> 02:59.770
Like this.

03:01.710 --> 03:02.670
Because of the stick.

03:02.670 --> 03:11.040
And here we will add width format csv, csv either.

03:12.270 --> 03:14.640
And we will also add the limiter.

03:14.670 --> 03:16.650
The limiter is going to be this.

03:18.080 --> 03:18.360
Pipe.

03:18.890 --> 03:19.650
That's it.

03:19.670 --> 03:21.050
So here.

03:21.950 --> 03:25.730
We define three character columns in this.

03:26.580 --> 03:27.930
Yeah, actually, that's me.

03:29.310 --> 03:30.270
Leather here.

03:30.270 --> 03:30.990
Leather here.

03:30.990 --> 03:32.330
So, see more?

03:32.730 --> 03:33.100
Yes.

03:33.120 --> 03:33.900
Perfect.

03:34.060 --> 03:34.560
Right.

03:35.720 --> 03:39.030
And open the can also jinxx.

03:39.230 --> 03:39.890
Perfect.

03:39.980 --> 03:44.360
So here we define three character columns here.

03:47.510 --> 03:53.960
Um, and this we define the three character columns of different types and insert two rows of the same

03:53.960 --> 03:58.040
string into, into each year after that.

03:58.160 --> 03:59.060
That's it.

04:00.290 --> 04:06.770
And unlike the insert into statement you learned in previous lectures here, we are not specifying the

04:06.770 --> 04:07.850
names of the columns.

04:07.850 --> 04:13.670
So if the value statements match the number of the columns in the table, the database will assume you

04:13.670 --> 04:17.330
are inserting the values in order the column definitions here.

04:17.330 --> 04:23.660
So in this case the ABC first ABC goes to the character column, the second goes to VARCHAR and the

04:23.660 --> 04:26.030
third goes to text here.

04:26.030 --> 04:37.280
So next we use the PostgreSQL copy, keyword copy keyword to export the data to a text file named desk.

04:37.820 --> 04:49.190
We didn't actually use the task text file here, so my new lecture dot text file and here we will add.

04:49.280 --> 04:58.820
So we are exporting the data to a text file named my new lecture in a directory of desktop here.

04:59.060 --> 04:59.870
So.

05:00.830 --> 05:06.800
And you will need to replace your directory with the full path to the directory on your computer where

05:06.800 --> 05:08.660
you want to save that file.

05:08.660 --> 05:15.230
And the examples in this course, use the Windows formats, which is use backslash between the folders

05:15.230 --> 05:21.500
and file names and the path directory on the C drive.

05:21.500 --> 05:24.470
So if you are using Linux, you should write something like this.

05:24.470 --> 05:33.110
For example, Home Oxley desktop and my text file dot txt like this.

05:33.140 --> 05:38.600
In this case we are on Windows, so that's why we write the backslash and see this here.

05:39.020 --> 05:46.100
So Windows user must set permissions for the destination folder according here and now.

05:46.100 --> 05:47.690
Let's run this here.

05:48.460 --> 05:55.180
And as you can see here, we got an error because of the syntax at or near here.

05:55.360 --> 05:57.880
So that's because of the reduce.

05:57.910 --> 05:59.740
We need to use this.

06:01.220 --> 06:02.440
Parentheses instead of this.

06:03.760 --> 06:03.900
I.

06:04.600 --> 06:06.040
And we also have syntax errors.

06:06.070 --> 06:07.900
Of course, we we don't need that.

06:10.430 --> 06:15.130
Insert into character syntax error at once.

06:16.210 --> 06:18.020
So could not open the file.

06:18.040 --> 06:19.150
Permission denied.

06:19.180 --> 06:22.930
That's the error that I wanted to show you here.

06:22.930 --> 06:28.000
So now we're going to fix that error via our permission is denied now.

06:29.820 --> 06:33.220
And here, as you can see here, we got this error here.

06:33.240 --> 06:37.530
So in order to fix that, you will go to your the destination folder.

06:37.530 --> 06:40.920
In this case, it's a desktop, my new lecture.

06:40.920 --> 06:46.740
And here we will right click on that, click on properties and click on security.

06:47.100 --> 06:50.190
And here we will use edit.

06:52.440 --> 06:55.320
And here we will write everyone.

06:55.440 --> 06:57.120
Everyone click on.

06:57.120 --> 06:57.870
Okay.

06:57.960 --> 07:01.560
And here you will have this options here.

07:01.740 --> 07:06.210
So you will allow the modify and click on apply.

07:06.210 --> 07:10.050
In this case, this might ask some questions here.

07:10.260 --> 07:10.740
Just click on.

07:10.740 --> 07:12.750
Continue, continue.

07:13.110 --> 07:13.980
Continue.

07:14.400 --> 07:14.850
Continue.

07:14.850 --> 07:18.480
Again 4 or 5 times it might ask you.

07:27.280 --> 07:27.880
That's it.

07:28.760 --> 07:29.540
Here now.

07:29.540 --> 07:34.100
Our error will be fixed now and click on this.

07:35.210 --> 07:40.930
As you can see here, we got successfully returned from our query.

07:40.940 --> 07:44.780
So now we're going to go to as you can see, our file is here, right?

07:44.780 --> 07:45.920
So click on that.

07:45.920 --> 07:50.390
And as you can see, we are brought to that here.

07:50.390 --> 07:57.050
So in PostgreSQL here, I will also explain this.

07:57.810 --> 08:01.200
Let's actually open with the Visual Studio.

08:01.800 --> 08:03.630
Now Visual Visual Studio code.

08:05.580 --> 08:05.850
Here.

08:05.850 --> 08:10.080
We will right click on that open with Visual Studio code.

08:11.160 --> 08:11.630
That's it.

08:11.640 --> 08:22.290
So in PostgreSQL, the copy table from here, the copy table name copy card data types to.

08:23.580 --> 08:25.560
And copy from.

08:27.000 --> 08:30.580
Is the input function and the copy table name character.

08:31.110 --> 08:36.690
Two is the export function, so I will cover them in depth in next lectures.

08:36.690 --> 08:43.470
For now, all you need to know that is that here we have character table insert into copy to.

08:44.420 --> 08:45.860
And here and width here.

08:45.860 --> 08:54.320
So you will also make sure that so this width keyword options will format the data in the file with

08:54.320 --> 08:59.180
each column separated by this pipe character.

08:59.180 --> 09:07.370
So that way you can easily see where spaces fill out the unused part of the column.

09:07.370 --> 09:16.820
So to see the output you open the our mining lecture that takes or whatever your file name in that case.

09:16.820 --> 09:22.520
So here, as you can see here, one, two, three, four, five, six, seven, eight, nine, ten.

09:22.550 --> 09:30.020
We have ten characters and almost one, two, three, four spaces and here we have ten characters as

09:30.020 --> 09:30.380
well.

09:30.380 --> 09:32.420
And here we have seven spaces.

09:32.510 --> 09:39.680
So even though you specify ten characters for both of the char character and var character columns only

09:39.680 --> 09:45.240
the car columns outputs ten characters in both rows.

09:45.240 --> 09:47.100
Here you can see here.

09:47.970 --> 09:51.090
So padding and use characters with spaces, as you can see here.

09:51.090 --> 09:55.410
But in other cases there is no such practice, right?

09:55.500 --> 10:01.140
So again, there is no real performance difference among the three types, although this example shows

10:01.140 --> 10:05.730
the character car can potentially consume more storage.

10:06.900 --> 10:10.050
This can potentially consume more storage.

10:11.710 --> 10:15.880
Then, um, other, uh, characters here.

10:15.880 --> 10:20.380
So then actually that's not needed in most cases.

10:20.380 --> 10:27.220
So if you use spaces in each column might seem negligible, but multiplying that over millions of rows

10:27.220 --> 10:31.900
in dozens of tables and you will soon wish you had the more economical.

10:31.900 --> 10:38.230
So I need I tend to use text on all my character columns.

10:38.650 --> 10:45.250
This text here that saves me from having to configure maximum length for multiple character columns

10:45.250 --> 10:53.410
and means I won't need to modify a table later if the requirements for a character column change.
