WEBVTT

00:07.910 --> 00:12.200
Let's go out here and learn how to insert data into a table in PostgreSQL.

00:12.230 --> 00:16.520
So to insert the type of table, we need to use a keyword.

00:16.520 --> 00:19.400
And that keyword we're going to use is called insight.

00:19.430 --> 00:24.740
And the insight into the table and the table name is a student.

00:27.560 --> 00:35.240
So students and then because we have the primary key already autoincrementing at ease the stress id,

00:35.390 --> 00:40.160
I want to insert this on the the first, the first name.

00:40.160 --> 00:45.980
So first name last name then the GP.

00:46.490 --> 00:54.200
And one thing is that a GP has a precision of one by one means that is not going to be more than one.

00:54.200 --> 01:02.120
So we're going to insert only 0.9 or 1.0 or 0.8, 0.7 or 0.5.

01:02.120 --> 01:08.360
So if you want to increase that to like 4.7, 2.5 for Namazga-tepe, you're going to increase the precision

01:08.360 --> 01:15.740
and the scale to maybe like a 3 or 4 by anything.

01:15.740 --> 01:23.540
So you can start maybe precision of a five by 5 or 2 by five or so on.

01:23.540 --> 01:27.950
But if you use precision of one by one, just like we did when we created this table, we're going to

01:27.980 --> 01:33.800
be limited to only 0.9, 0.8, 0.7 and so on, or 1.0.

01:33.830 --> 01:34.460
Okay.

01:34.460 --> 01:40.700
So the next one is that we're going to enter the a row underscore date.

01:40.700 --> 01:43.820
And then the email we're going to set the email.

01:44.570 --> 01:49.250
Now we need to add values because I've not entered the semicolon.

01:49.250 --> 01:51.350
So I'm still working on that.

01:51.350 --> 01:53.630
This okay until I enter the semicolon.

01:53.630 --> 01:55.640
That is when this query was executed.

01:55.640 --> 01:59.560
So Values and what values they were.

01:59.560 --> 02:04.300
First name there is going to be Peter, so that is for the first name.

02:04.330 --> 02:10.270
Peter entered into the first name, and then the last name is going to be Jude.

02:10.270 --> 02:17.980
And close the quotation mark and we go ahead and enter the GP.

02:17.980 --> 02:21.220
So the GP is not going to be more than one.

02:21.220 --> 02:26.440
So 0.9 if you enter anything like 4.7 you're going to get an error accepting.

02:26.440 --> 02:34.240
Please, you cannot increase your precision to like a four by 3 or 4 by an anything or one by anything

02:34.270 --> 02:35.140
and so on.

02:35.140 --> 02:37.090
But for now we get one by one.

02:37.090 --> 02:43.360
You're going to be limited to only 0.9, 0.8, 0.7, 0.5, 1.0.

02:43.390 --> 02:44.770
And you can go on and that.

02:44.800 --> 02:50.290
Now that is not really good for GP because no GP can be 0.1.

02:50.290 --> 02:52.300
That is, you're really way too small.

02:52.300 --> 02:58.780
So the in red dates we're going to see dates and the text is going to start by the year.

02:58.810 --> 03:11.680
And let me say it is a 2019, 2019, and the month is a February zero two and the day is zero six.

03:11.680 --> 03:15.610
And go ahead and, uh, enter the email.

03:15.610 --> 03:17.740
So let me say the email is going to be Peter.

03:17.740 --> 03:24.520
And uh, let me say Peter Jude at uh gmail.com.

03:24.520 --> 03:28.480
But see if this is going to be inside a single quote.

03:28.480 --> 03:39.610
And I'm going to say Peter, Jude at gmail.com and the quotation mark, and then go ahead and close

03:39.610 --> 03:39.910
this.

03:39.910 --> 03:41.920
And I'm going to put a semicolon at the end.

03:41.950 --> 03:46.960
And now that I've entered the semicolon, it means that I can now go ahead and execute this query.

03:46.960 --> 03:48.280
So go ahead and hit enter.

03:48.280 --> 03:52.300
And you can see we have insights zero one.

03:52.300 --> 03:55.440
And then let's go over here and check it out.

03:55.440 --> 03:57.540
So select all from students.

03:57.540 --> 04:01.680
And if I execute this query let's go ahead and you can see stress ID.

04:01.920 --> 04:10.380
The first one here is the ID the stress ID and the primary key one the first name Peter.

04:10.410 --> 04:13.500
The last name Jude GP is 0.9.

04:13.500 --> 04:22.260
And the erode date is uh these 29 00206 and email is this.

04:22.290 --> 04:29.280
Now I can go ahead and insert a SQL one if I go ahead and copy everything right in here.

04:29.310 --> 04:30.990
Let's go ahead and copy everything here.

04:30.990 --> 04:34.800
And now you can see that I copied that twice.

04:34.800 --> 04:37.350
And anyway it says terminates bad job.

04:37.380 --> 04:39.990
It can go ahead and say yes or no.

04:40.020 --> 04:44.730
But because I've copied that twice and I'll go over to show and continue from here.

04:44.730 --> 04:47.610
So let's go ahead and show you how to do that from this place.

04:47.610 --> 04:50.400
So I'll go ahead and paste what I just copied.

04:50.400 --> 04:53.550
And that is insights from students.

04:53.610 --> 04:54.960
Go ahead and increase this.

04:54.960 --> 04:58.650
And uh, I'll go ahead and add the values.

04:58.650 --> 05:00.570
So go ahead and add values.

05:03.810 --> 05:10.260
So the values now want to add is uh open and close with a semicolon at the end.

05:10.260 --> 05:12.060
And there are a warhead.

05:12.060 --> 05:17.670
And the first one of the themes I just have then a warhead and it did that.

05:17.670 --> 05:21.180
So I have the first name to be Barak.

05:21.210 --> 05:22.410
Then ask them to be Harry.

05:22.410 --> 05:29.340
And uh, like I told you, the GMO is not going to be more than the zero points, is open to more than

05:29.340 --> 05:29.760
one.

05:29.790 --> 05:36.060
All right, then, go ahead and say that, uh, it's going to be like a 0.8.

05:36.060 --> 05:38.370
And then this is the date.

05:38.370 --> 05:41.640
And for the dates we go ahead as a date.

05:41.640 --> 05:47.100
And this is going to be single quotation Mark is going to use single quotation mark.

05:51.620 --> 05:52.100
All right.

05:52.100 --> 05:52.820
So.

05:57.410 --> 06:01.550
I'm going to do this without an email because the email is nullable.

06:01.580 --> 06:02.150
All right.

06:02.150 --> 06:05.780
And if I actually run this code I'm going to get this inserted right in here.

06:05.810 --> 06:08.600
So if I go ahead and run this let's go ahead and check it out.

06:09.770 --> 06:14.780
It says insert has more target colon than expression.

06:14.780 --> 06:17.630
And uh insert into these.

06:17.630 --> 06:24.980
We have the GP, we have enrolled date and we have the email is pointing to the email that we need to

06:25.010 --> 06:31.850
insert the email now because I don't want to insert into the email, I'll go ahead and remove this email.

06:31.850 --> 06:35.420
And now I'll go ahead and uh click on this.

06:35.420 --> 06:36.860
And I have the email.

06:36.890 --> 06:46.340
Now what if I don't want if I want to insert this and uh, let me go ahead and remove the last name.

06:46.370 --> 06:48.200
Let's go ahead and remove the last name.

06:48.650 --> 06:54.200
So the last name is removed and, uh, I'm going to change the first name.

06:54.230 --> 06:58.070
And let me say the first name is going to be Sarah.

07:01.040 --> 07:08.450
And then let me see, the last name is going to be equal to Rocky.

07:08.600 --> 07:13.700
And let me go to um, 0.7.

07:13.700 --> 07:18.290
And we change the enrolled date to 2090.

07:18.320 --> 07:27.800
And uh, let this be ten and let this be five.

07:27.920 --> 07:32.990
And now let's go ahead and insert this and execute this query.

07:32.990 --> 07:37.490
And you can see insert has more expiration than target.

07:37.520 --> 07:46.540
And uh look what happened actually is that I have Rocky and I need to remove that so that's we can actually

07:46.570 --> 07:49.180
deal with that's the last name.

07:49.180 --> 07:50.770
Then we'll go ahead and execute this.

07:50.800 --> 07:56.020
And it says third row contains three DS value encoding.

07:56.020 --> 08:01.300
Last name of Russian students violates not no constraint.

08:01.510 --> 08:03.640
So you see that not no constraints.

08:03.640 --> 08:05.380
So no value in column.

08:05.380 --> 08:09.370
Last name of Russian students violates not null constraint.

08:09.400 --> 08:13.570
But what we entered the email we are able to actually enter the email.

08:13.570 --> 08:18.040
And nothing actually happens because the email is nullable.

08:18.070 --> 08:24.760
But we are not expected to enter any data with the last name.

08:24.760 --> 08:26.440
So the last name must always be there.

08:26.470 --> 08:30.520
I just wanted to enter the first name, the GP and erode date.

08:30.520 --> 08:34.750
And uh, I didn't add the last name, but it's not possible.

08:34.750 --> 08:37.210
But you can do that without the email.

08:37.240 --> 08:37.870
All right.

08:37.870 --> 08:42.010
So this is the difference and why the constraint is always there.

08:42.010 --> 08:48.850
You can no longer insert any data without first name, last name, GP or erode date, but you can insert

08:48.850 --> 08:54.580
the data with a out, an email and it will go on and work out fine.

08:54.580 --> 09:01.570
Now if I go ahead and add last name, let me go ahead and add last underscore name.

09:01.570 --> 09:04.870
You can see that Sarah is not added.

09:04.900 --> 09:05.650
All right.

09:05.650 --> 09:15.370
So what actually happens while the uh form it increments from one to 2 to 4.

09:15.370 --> 09:22.840
And instead of three is because this primary key actually incremented when it's wanted to add this.

09:22.840 --> 09:25.960
And it can't go back to three anymore.

09:25.990 --> 09:26.350
Right.

09:26.380 --> 09:33.070
So it's moved over to four because Sarah is omitted the last name.

09:33.280 --> 09:38.590
So it has already created the key and found out that it's missed.

09:38.920 --> 09:44.100
There are no constraints or it violates less a no constraint and that is why it didn't add it.

09:44.130 --> 09:50.220
Now it has a primary key of, uh, one, two and four and instead of three.

09:50.760 --> 10:01.500
So now you can see that you cannot be able to add anything without adding what a first last GP and enroll

10:01.500 --> 10:02.340
date.

10:02.700 --> 10:09.630
So that is the function of the no constraint making sure that we add everything complete.

10:09.660 --> 10:10.140
All right.

10:10.140 --> 10:18.060
So without adding everything complete it means that we cannot insert that data into our table except

10:18.060 --> 10:18.750
the email.

10:18.780 --> 10:21.030
Because email is nullable.

10:21.030 --> 10:23.370
So go ahead and practice with this and check it out.

10:23.370 --> 10:26.700
And if you have any question or how do I use the question and answer section.

10:26.700 --> 10:29.310
And I'm going to get back to you as soon as possible.

10:29.340 --> 10:30.270
Thank you so much.

10:30.270 --> 10:33.180
And I'm going to see you in the next video lecture.
