To see these three character types in action.
We will code some script here.
So firstly, we will create the table and let's name it character data types, right?
So create table and name it MyCar or yeah, character data types.
Character.
Data archives.
And here we will add character.
I will explain all of this with column Character is going to be ten.
And the character after that is Comma.
So our character.
Var character column is going to be var character type, also ten and we will also add text.
So text column column is going to be text.
Just a text here and we will not define size because as we told, as I as you learned in previous lecture,
that variable length column of text is has unlimited length.
So that's why we didn't wrote anything onto this.
And here we will use after that we will insert here, insert into character, oops, insert into car
card data types, types and values insert into values of.
A, B, C, for example.
That's it.
A, B, C.
And after that, we will also enter ABC again.
ABC again and ABC again.
And that's actually due in part to my pen ink here.
And here we will also after that we will add a comma, and after that we will also add the DFG.
The a f g def.
We'll copy that.
Yes, again.
That's it.
Here.
And we will copy.
Copy.
Uh, character data types.
To and we will set the directory here.
In this case, we can also set our directory into the desktop I guess.
Yeah, we can use the desktop here.
We will.
Instead of this, we can also go to this and users Oxley.
And after that, we'll add desktop here.
That's it.
And copy this to our desktop and after that.
So of course we need to write this in quotes.
Like this.
Because of the stick.
And here we will add width format csv, csv either.
And we will also add the limiter.
The limiter is going to be this.
Pipe.
That's it.
So here.
We define three character columns in this.
Yeah, actually, that's me.
Leather here.
So, see more?
Yes.
Perfect.
Right.
And open the can also jinxx.
Perfect.
So here we define three character columns here.
Um, and this we define the three character columns of different types and insert two rows of the same
string into, into each year after that.
That's it.
And unlike the insert into statement you learned in previous lectures here, we are not specifying the
names of the columns.
So if the value statements match the number of the columns in the table, the database will assume you
are inserting the values in order the column definitions here.
So in this case the ABC first ABC goes to the character column, the second goes to VARCHAR and the
third goes to text here.
So next we use the PostgreSQL copy, keyword copy keyword to export the data to a text file named desk.
We didn't actually use the task text file here, so my new lecture dot text file and here we will add.
So we are exporting the data to a text file named my new lecture in a directory of desktop here.
So.
And you will need to replace your directory with the full path to the directory on your computer where
you want to save that file.
And the examples in this course, use the Windows formats, which is use backslash between the folders
and file names and the path directory on the C drive.
So if you are using Linux, you should write something like this.
For example, Home Oxley desktop and my text file dot txt like this.
In this case we are on Windows, so that's why we write the backslash and see this here.
So Windows user must set permissions for the destination folder according here and now.
Let's run this here.
And as you can see here, we got an error because of the syntax at or near here.
So that's because of the reduce.
We need to use this.
Parentheses instead of this.
I.
And we also have syntax errors.
Of course, we we don't need that.
Insert into character syntax error at once.
So could not open the file.
Permission denied.
That's the error that I wanted to show you here.
So now we're going to fix that error via our permission is denied now.
And here, as you can see here, we got this error here.
So in order to fix that, you will go to your the destination folder.
In this case, it's a desktop, my new lecture.
And here we will right click on that, click on properties and click on security.
And here we will use edit.
And here we will write everyone.
Everyone click on.
Okay.
And here you will have this options here.
So you will allow the modify and click on apply.
In this case, this might ask some questions here.
Just click on.
Continue, continue.
Continue.
Again 4 or 5 times it might ask you.
That's it.
Here now.
Our error will be fixed now and click on this.
As you can see here, we got successfully returned from our query.
So now we're going to go to as you can see, our file is here, right?
So click on that.
And as you can see, we are brought to that here.
So in PostgreSQL here, I will also explain this.
Let's actually open with the Visual Studio.
Now Visual Visual Studio code.
Here.
We will right click on that open with Visual Studio code.
That's it.
So in PostgreSQL, the copy table from here, the copy table name copy card data types to.
And copy from.
Is the input function and the copy table name character.
Two is the export function, so I will cover them in depth in next lectures.
For now, all you need to know that is that here we have character table insert into copy to.
And here and width here.
So you will also make sure that so this width keyword options will format the data in the file with
each column separated by this pipe character.
So that way you can easily see where spaces fill out the unused part of the column.
So to see the output you open the our mining lecture that takes or whatever your file name in that case.
So here, as you can see here, one, two, three, four, five, six, seven, eight, nine, ten.
We have ten characters and almost one, two, three, four spaces and here we have ten characters as
well.
And here we have seven spaces.
So even though you specify ten characters for both of the char character and var character columns only
the car columns outputs ten characters in both rows.
Here you can see here.
So padding and use characters with spaces, as you can see here.
But in other cases there is no such practice, right?
So again, there is no real performance difference among the three types, although this example shows
the character car can potentially consume more storage.
This can potentially consume more storage.
Then, um, other, uh, characters here.
So then actually that's not needed in most cases.
So if you use spaces in each column might seem negligible, but multiplying that over millions of rows
in dozens of tables and you will soon wish you had the more economical.
So I need I tend to use text on all my character columns.
This text here that saves me from having to configure maximum length for multiple character columns
and means I won't need to modify a table later if the requirements for a character column change.