In this complete PostgreSQL tutorial, you'll learn every practical way to insert data using PGAdmin 4 from beginner to real-world level. We’ll start with inserting single records, then move to inserting multiple rows efficiently, handling duplicate conflicts using ON CONFLICT, and finally import Excel/CSV files directly into PostgreSQL.
If you've ever searched:
✔ How to insert data in PostgreSQL ✔ How to insert multiple rows in PostgreSQL ✔ How to import CSV into PGAdmin4 ✔ PostgreSQL INSERT INTO tutorial ✔ PostgreSQL bulk insert guide
Then this video covers everything in one place.
What you'll learn:
✅ INSERT INTO syntax explained ✅ Single row insertion ✅ Multiple record insertion ✅ Understanding table structure and columns ✅ Handling duplicate/conflict data ✅ ON CONFLICT DO NOTHING explained ✅ Import Excel/CSV directly into PGAdmin4 ✅ Practical PostgreSQL examples
⌛TIMELINE⏳ 00:00 Introduction — Insert Data in PostgreSQL using PGAdmin4 00:14 Different Ways to Insert Data in PGAdmin4 01:45 Insert Data Theory & Syntax Explained 03:36 Support the Channel ❤️ 04:30 Understanding Tables & Columns Before Inserting Data 07:20 Insert Single Record into Departments Table 08:45 Verify Inserted Data in Table 09:30 Insert Multiple Records at Once 13:15 Handle Duplicate Data & Conflicts During Insert 15:45 Important PostgreSQL Tip Most Beginners Miss 19:20 Import Excel / CSV File Directly into PostgreSQL using PGAdmin4 22:00 Final Notes & Practice Challenge
AI Generated·May contain errors
Video Summary
AI Generated
This tutorial provides a comprehensive guide to inserting data into a PostgreSQL database using pgAdmin 4. It covers manual SQL insertion methods, strategies for handling unique constraint conflicts, and the professional process of importing large datasets from CSV files, including common troubleshooting tips for data mapping and file formatting.
Hello, what's up, guys? Welcome to day 4 of the PostgreSQL series.
And in this video, we are going to see how to insert data into our database using pgAdmin 4.
and I will tell you different ways through which you can insert data
And let me tell you, you're going to have a lot of fun.
Here you can see, I have shown you ways to insert data.
You can insert a single data item or a single entity.
A single new record is also written.
Then you can do multiple records
You can insert multiple records together.
batch, insert basically
the clause that returns now basically means
whatever data you have inserted together
now if you want to cache it immediately
or if you want to use it in the backend
the ID that it will return
For that, you can use this RETURNING clause
And then, at the end, we have this conflict clause.
Believe me, it will be very useful for you.
where, let's say, you have inserted thousands of data
Once again, you receive new fresh data.
and you realize that there are a lot of duplicates
So you're not going to leave it.
So what you are going to do is
You are going to insert all of them.
but write this command
If there is a conflict, then do nothing.
and if there is no conflict
The duplicate will be inserted.
It won't do anything.
means without any mistake
Your query will be executed successfully.
So these four methods are manual approaches.
but how professional are they, really?
that I will tell you
that is with the help of guys
importing massive data
You can do it directly through pgAdmin 4.
This is the step.
or you can do it directly through the CLI
in this way your query
basically command
if you do it by writing this
then your work will also be done
So I will share everything with you in this video.
And you're going to have a lot of fun.
OK
and whoever is interested in directly practical
So guys, you can skip this and go to theory.
directly practical
but I thought
To tell you a little practically
I mean a small theory
so that you may come to know
when we write it in practice
What is happening?
What is the value of syntax?
What does it mean?
OK
so you can see
It's very simple here.
how can we insert
like the single record
so we have this insert
Table name
by the way in MySQL
It was the same.
There is no difference.
Insert into table
and these are the column names
These are the column names.
which you have already created
in tables
the column name in that
Is this
then we have these values
In values there is s
Remember this.
Many people miss S.
They think
when it comes to single data
Then why should I write?
This happens.
Remember this.
and then simply
You must enter a value here
That's it.
Just make sure
whatever value you are writing here
You see this?
its value should match this
This value should match this.
and this
The value should match this.
This is very important
so whatever column you have written in the first place
whatever column name you are writing in first
and when after value
Your first value will match this.
I mean
Its data will be called this.
So remember this
It shouldn't happen that
Here you have written the name.
Here is the email.
while providing value
You are sending an email
and then you are giving it its name
So it will be inserted.
because both are strings
or it will be inserted into the variable character
that data type
but that data is incorrect
so make sure this
and at the same time
See this
I have told you
And this is how you can do it
See this
These are different ways.
to do it
id in id
name in name
and then grade in grade
Alright
Let's do one thing.
Let's go directly to our pgAdmin 4
Let's work there.
but before that
if you haven't checked out
previous videos
then I highly recommend
to check it out
You will like it a lot
Alright
and please if you like the video})();
then like it
with 500 likes
your one like
will motivate me a lot
like this
in the AIK era
Keep uploading videos
in free
because
AI will do it
but if you don't learn
from this
That AI will do it
then
You have no work.
I mean
If you go to work
What will you say?
I do everything through AI.
but nothing comes
I mean
You understand
You don't want that
You have to
Make your base
stronger
You have to go.
in greater detail
You have to go.
from programmer
to developer
I mean
There are a lot of things.
that's why
learning all this
It is important.
Then we will go.
in the end
We will see AI
and please
if you haven't subscribed
Then subscribe
because
This is the source
of motivation
Alright
so now
Let's go straight ahead.
to our PG Admin 4
Alright
so in yesterday's video
I showed you
that
I made the
users table
and showed you
so you can see
what I have done
I have created
a separate table
in the department
You can copy and paste.
and then we have
this users table also
and don't worry
I will share the source code
Below is the file.
you can
Use it easily
Alright
so that you don't
ificação
because up until now
we have
these references
I haven't told you
but when I created
Let's proceed professionally.
way
when the right time
will come
to tell you
Then I will tell you
right now
We have a department.
and then we have
a user
in the users table
We have this.
id
Name
email
role
See this role
It is very important.
Here
and on the basis
of this role
we will define
whether the
users are
students
or professors
or admin
Alright
will be very
useful later
whereas instead of
three separate
tables
we can use
one table
Alright
And by the way
I have the
complete data
and here you can
See clearly
that I have
the complete data
See
later
In this video
I will insert
and show you
so you don't
worry
Alright
so everything
will come here
and this is
department
id
because we have
Already created
department here
that's why
We have this.
Department ID
then only
relationship will
sit between
Later we have
to read
relationship
one to many
many to many
or foreign
primary
then this
metadata
right now
you don't
Pay attention
to this
what is
this data
type
jsonb
as you have
heard
What is this?
at the end
then is active
created
Alright
so these
two tables
right now
We should have
Make sure
You do it
Alright
So let's go.
with department
when we insert
then how can we
Do it in one.
way
how can we
Do it in multiples
way
We will see.
and then
We will see.
conflict
and then
simple
table
directly
CSV file
directly
insert
100 data
in one
time
so
I will copy
department
so
I have to
simple
insert
single
record
insert
Alright
see
insert᠆
into
table name
Alright
Here
You have to
insert value
we have
ID and
Name
And by the way
if you see
Our ID is
serial data
type
serial means
1, 2, 3
It will do.
automatically
so we don't
need to
we just
need to
Add this
Name
field
so let's
go with
Name
Here you have.
to write
values
and then
Don't forget
to give
a value
so
Here
to give
no
are
Okay
so
I have
listed
data
here
so
you have
to
give
value
here
so
you have
to
give
value
here
so
departments or its name has been established
There should no longer be any problem with values in computer science.
Yeah, and this is it
So how does it look?
Look here, look at this
Something like that output comes out, okay
insert 0 and then 1
Meaning, a data insert has been made.
Query returned successfully in 25 milliseconds
Nothing is showing up in the data output.
There is nothing in the notification
It is shown in the message
Has this data been inserted or not?
How can we check him now?
how to read the data
It's simple, just like we had in MySQL
I am assuming that
Some people also know MySQL
select star
Meaning every
column Everything
Just like Phila, there's only one here by name
but here everything is in all columns
from which table
From the table with departments
select every column
from our department
departments table
And here it is, look here
Just now, not yet
I had inserted this very one; if you remember
Look at this computer science
Isn't it so in this way?
You are at your table
You can insert data inside.
Guys, congratulations, Kiji
This is very awesome.
It's delightful to see such a sight.
Show me your data inserted into the database
Now that's
It became a single
Let's say you had to perform multiple data inserts
multiple records or data
Inserting it will be up to you
So, you see, it's simple, same as this.
insert
your table here
You must give me your name anyway.
will fall column which column
Look, Khalil is right now like this
that you have only one column nearby
Alright, if I am to do this in the users table
Wasn't it name, email
role, department
ID, metadata — we won't be looking at these right now
and then is active these all
I have to write all of this here
And something else too
So make sure
Look here how
name, email
role, department ID
You understand
How do I say it?
There isn't anyone in this sequence, though.
No, this is not in any order.
but the thing is when you are here
Writing like this
and if you write values tomorrow
When you write in this way
So name, suppose
There is a contradiction, isn't there?
then email
at the rate codifier.com
We are taking online classes and right now
I'm thinking about starting online classes from June 1st.
full stack with AI
Let me know in the comment section how many of you are interested
then is active in
I'll keep one for myself.
Department ID, let's go, we still have one
Makes it true
So this is my simple example to show
What I meant was that if your
If the first column is name then
Value will also be a name, isn't it? The email is dancing.
The email must be active.
If the department ID is active, then the department
ID, make sure to confirm it
If possible, table
When you create, not like a name
I mean, name, email, role—those are the same.
Try writing it down
So that it's easy for you, okay?
Don't make separate entries because name, email, then
It is active forward while it is at the very end, okay?
This is just to show you, you can do it this way
But Philal in our case
Now I need to perform multiple inserts.
We have a name, then values.
Now look, what you've done here
No problem here.
If you need multiple, then comma
parentheses comma
parentheses, comma, and then
semicolon means just
comma, see you and
New extra from the record, to him
You can add it, okay
and by the way, there's something I need to mention
Read the data, okay?
id name and I work
Because you've now figured it out this way
Isn't it just one second?
Cancel it and check the ID
I've set the name, second, look it up
It has already become the default first here.
If it seems so to you, then it is, isn't it?
I already have one here, that's fine.
So second, this will be mine
third fourth fifth
So I am now at the same time
I am inserting four records at once.
So this is much better, isn't it?
Go there and then
Hit it so my query
This task is done again, I'm doing it
I'm copying it, I mean, not copying this one, me
When I run here, there's a lot
You can clearly see now
That's it, so ours
The department person who had that table
In it, I also did it in a single way
Show me by inserting and also in multiple ways
And that became my job, one two three four five
And our data is perfectly set right here.
Perfect. Alright, this is mine.
It's done, okay. Now I've got one thing
returning to the one
We'll see when the right time comes.
Isn't it that our back-end right now?
I may not even need him anywhere.
I'm basically talking about this.
This one here
Returning clause, okay? Just for you
Returning ID, please write something
You will have to write the column name, yours will be done
But we don't really need it that much.
This one with on-conflict
What is, see it — it's important how to look.
As if this were a query
So, what am I supposed to do here?
The same data as before
I would like to insert, so I have a command
I'm writing now, this time meaning I'm saving
If it feels like to you
Everything else is fine, but
This one, which is a field, is a conflict.
If it shouldn't be, then you give it a name.
You will mostly give your email ID
You're giving this phone number, aren't you, because it should be unique?
The email ID matters the most
But in our case, it's only its name
do nothing
If there are conflicts, names
Just don't do anything.
If one second
First, I just run it
If I had gone back
The data that has already been inserted
I will insert it back after returning.
I am saying
So, what happens? I'll show it to you.
Look what happened
Look here, you fool
in the message
What is coming to me?
I am getting an error
Over here, see the error.
Duplicate key value violates unique constraint
Duplicate value is indicated
Look, a key with ID equal to 2 already exists
So you're seeing it, aren't you?
that you get errors in this manner
When you same data
The one that has already been inserted
If you're going to insert anything, do it
If a single line had been written
Which one is in conflict?
Column name, do nothing
Alright, if suppose here
Name or email
Yes, and if I hadn't written an email
Yes, and the email is a duplicate.
So it won't do anything because here
The one who gives it will be the one checking it.
So if I write this
I mean, here
At least you won't get that error
And it is also very useful.
Doing a job
I do a job.
and that is quickly
This departments thing
table him
I'm dropping it.
I want to show you something
And by the way, what's going on here?
cannot drop table department because
The other object depends on it.
Constant Users Department
ID for it
The thing is, I'll have to delete this first.
I mean, I'm dropping this one too.
For you guys
I'm dropping everything, and this is how
I think that
You will learn.
Drop it, then learn, then observe, then trial and error
Now I'm also dropping this.
Because I need to see him
In case of conflict, if the one
I already have the data; I want to show it to you.
My work is done this way.
No tension, I'm coming back.
I'll take care of it, run
I'll do it again from the beginning. run
You're not having any problem, right?
It's a line; I'm going back
Alright, I'll take it.
Data will now be inserted in reverse order.
So there's no tension at all; if I drive it, it's fine.
So, you know, I've arrived.
I just want to take a break now.
here
This line here, translate this
I will copy it.
paste
I walk home on the 6th number
In this way, I'll keep computer science.
and the same piece of code
I am here.
I'll put it down; I need to see this.
I know what's going to happen.
You don't happen to know, do you?
So I need to see this for myself
So what's left of this?
Valid means exactly this
Not inserted yet, nor is this completely raw
Is this a fresh date? Will it be inserted?
No, it won't happen.
I don't know, let's check it out
I am speaking to you all.
Look at this
What is Aara here?
What did it mean?
Now I'll tell you, if I
I sing Selakk and Boom sang
That is exactly what I wanted to show you psz
Have you seen, I mean, have you seen?
How useful is that query
If
They do nothing during conflict.
You do not write that line.
So I don't think this all
are there, your entire
It all goes to hell, but look at this
What was common
Leaving aside the conflict that was taking place, the rest
It's useful, isn't it?
Whether or not you speak, tell me
This is fresh data indeed.
I also didn't have it inserted.
But at the end, I've added external data here
So what about this
Inserted or completely me
Error inserting anything today
No, it's okay, but
Look, it saved my life, our life
Understand where millions
When the issue of data insertion comes up, then there...
This will be very useful.
How to insert single data now
How to insert multiple data
How can you avoid conflict?
We have seen everything already.
Now, there's one thing we need to pay attention to, which is important for us.
and somewhere, somewhere, very much
It's a manual task, and when you
If you work professionally, then
Do you get the Excel sheet, or from somewhere?
You have already received the complete batch of data.
I need to import it directly here.
Look here, root!
Here I have my
It's data, isn't it?
Here I have the complete data, take a look
The first line is the
actual column name
Name, this, and rebel—this is all the data.
Look here, there's no admin from A to Z.
Any professor? Any students?
Yes, because that's exactly our role, isn't it?
Here I have a total of 100
You insert it for me
Inside my users' table
My work with the departments is done.
My work with the departments is done.
I need to insert this inside the ab users
So how will it be? Just wait and see.
I've shown you two methods here, by the way.
Here, if you look here
This has also become multiple.
By the way, this is it; I didn't show you this.
This one, the returning one
So, if you write this, you'll get this returned to you.
Which fields are in this table?
Belonging, like id
and then created at, then it will return to you
But that's fine, right?
And that's it, this is the way
There are two ways; you should try something.
I'll share it with you; I know you can't see this right now.
but for the time being, a second
No, look here, you see, this one
Copy and paste it, take a screenshot
You briefly appeared a moment ago
and it will be fun for you
How to do it, here we have
our users' table
I have the users table here.
So what will I do, right click
We have imported
and then export, very clearly
You can see, over here we have this
import and then export
So, what exactly do I have to do about this?
You'll have to click, okay, so
Right-click, import export
And that's it, look here, I've
Already the file name I have
This is my users.csv, I have it
Select here, I have selected the file name
and make sure you import
Here it is, not export, import
"Get" means to acquire, "export" means to send goods abroad
import, file name
format automatic
Got it, the rest is clear
Leave it as it is, and this
The one with options that you can see, this
It's very important, come here on this
and here, these headers of yours
You'll be“One, that's fine, you're good.
Turn it on, the toggle.
Yeah, you need to turn this on
Header, because what
What does this mean?
that if you
You're leaving here, so my very first
It's a line, my very first one
In the table, our column will be created
The one who stays at the top in the column, right?
My name, email, role,
Department ID, which is executive
I'm listing all their values below.
So, as a value
Treat it not like this, as a header
Okay, this is the column name, that's all.
The rest are below the second one
from line, as a value
It will treat, then it will turn on
Don't you ever forget, if you're here at this place
There are no headers in the first line
So, if your directly
If the value starts, there's no problem.
Leave it as it is, leave it off, no problem at all
Okay, and then in columns
When you go, so for
for some reason, by the way
Guys, it wasn't here, it was there
that they automatically enter it
the ones whose column names are mine
but for some reason, it did not do it
Here, do a job
Let's click OK.
Look, the process has failed.
Come to the process, by the way
I had already done it twice before, and
What is it saying here, invalid
input syntax
Is there a problem here or not?
This table of ours
In this table, we have a
id, then that one of yours
metadata, your created ad
But in my value here
What is ID? ID isn't anywhere at all.
So the value of id is one
It was serial, I've given it here, Deed Binu
Thapa, that's why he did it earlier
That's already wrong, you know—this ID is too short.
He blew it away, so I did
So I just wanted to tell you for a moment now
An automatic suggestion appears
Where, doing a job, I am one
I walk through the bar tables, and then
I'm refreshing, okay, do this one too
There's a refresh option, let's do this one too.
Refreshed, once again, users
Alright,
users, import
export
The file is already here.
PostgreSQL, okay, got it.
CSV is no problem, columns, headers
on, perfect
I didn't do anything, I just...
Refresh, because I feel something is wrong with the display.
Refreshed it; otherwise, open this
I'll open or close it, what else?
_digit, look, remove the ID,_
Because name is there, email is there, role is there,
Department ID, please remove the metadata
We have an IS active, and then created
Remove adcorp, because
The data here
We have given it, I mean, we haven't even given it at all
Yes, then write its column
and make sure name, email, role,
department, name, email, role, department id
is active, let's make sure everything is perfect, and then
Okay, and oh my God
How can this be? It simply cannot happen.
I needed it, sorry
Here, I need to see the top.
It indicates missing data for the column
email, context
copy users line 102
First of all, the thing is that
We have 100 data.
So, where is this 102 number from?
Yes, and the other thing is that
There is no problem at all, because
The columns that we need, we have
Select properly, Sara
data is equal, in fact, you can also see here,
I have already run it for him.
Finis is Finis, sitting comfortably having succeeded.
What's the problem here?
Let me tell you, look closely,
Missing data for column email,
He didn't get the data for the email,
at line number 102,
At number 102,
It basically says this is empty data
Alright, let's run it on VS Code.
This is our data, 102 here.
The first thing is that
That's all the data I have.
There's nothing in 102.
If you look closely at one thing,
When I'm caught up in the whirlwind of showing off to you all
I must have pressed enter.
After 104, look here,
There isn't any line visible to me here.
What is meant by this is that
102, 103, and 104
These are lines that do not contain data.
and csb when we are importing it, aren't we
So he's also come here.
Line number 102
Here he has come, and he looked.
There's nothing at all in this.
Anyway, do one thing for me,
Look here, looked at 104, gone,
103 gone, 102 gone,
There wasn't any problem at all.
But whatever it may be, if I want it
I will edit this part,
Doing so much from the return side,
It will be torn apart by importing.
But I won't edit this.
So that you people may know
Even due to such a silly mistake,
What problem is coming up, okay,
I will save this in the controller.
There's no problem now.
users, import
And I won't even look.
I'm just sitting here, idle, doing nothing.
No need for additional metadata.
Here, I'll stay.
Look here, the view process has been completed,
finished is equal to,
Let me check the luggage here.
Everything is correct, copy 100,
successfully completed
Remove it, come here.
Then I'm off to this.
I'm hitting it.
Here is Bonga,
This is it, look at this,
All 100 records have arrived completely.
Look here, it's exactly the same, isn't it?
Look here, everything you need has arrived.
Look here,
And by the way,
Here, here, this is the zoo,
It's happening because the ID starts from integer 201.
Because I had already inserted the data earlier,
Understand,
But then I deleted it again.
Therefore,
You want, if you need just one, two, three, exactly equal,
So there's no tension at all,
Do it all over again, dropping everything from the beginning.
Yeah?
But yes,
This is it.
My work is done.
Then we'll have a lot of fun ahead.
When executing SELECT queries,
We will update.
We will delete it.
acid
joins
You don't know his address,
So many things,
aggregation
It'll be fun, that's for sure.
aggregate function and all those things, right?
So, this is it,
That's it for today's video.
I hope you'll really like the video.
All of this that exists,