Now that you have learned how to create tables, you need to understand how to insert, view, modify, and delete data in the tables. This will help you update any incorrect entries, or update existing entries, as needed. There are a variety of commands that can be used for this, which we will look at now.
Inserting and selecting data
In this section, we will learn how to insert data into tables. To insert data into tables, you need to use the INSERT command. The INSERT command inserts new rows into a table. It is possible to insert one or more rows specified by value expressions, or zero or more rows resulting from a query. We will now go through some use cases as follows:
- To insert a new user in the users table, execute the following command:
forumdb=# insert into users (username,gecos,email) values ('myusername','mygecos','myemail');
INSERT 0 1
This result shows that PostgreSQL has inserted one record into...