Order INSERT INTO In PostgreSQL allows you to add one or more new lines to an existing table. Values must be specified during insertion
What is PostgreSql INSERT INTO ?
PostgreSql command INSERT INTO allowsInsert new lines into a table. You can insert a single line or more lines in a single order. As part of the use of PostgreSql INSERTthe columns defined when creating the table must be specified directly in the command.
Dedicated servers
Performance and innovation
Take advantage of your own server, with dedicated hardware, cloud integration, minute invoicing and Intel® Xeon® or AMD processor.
PostgreSql INSERT : syntax and operation
PostgreSql's basic syntax INSERT INTO is as follows:
INSERT INTO nom_de_la_table (colonne1, colonne2, colonne3, ..., colonneN)
VALUES (valeur1, valeur2, valeur3, ..., valeurN);
postgreSql
If you use PostgreSql INSERT INTOyou therefore first indicate the table in which you want to make your adjustments. Then come the different columns, although you can omit This list if you provide values for all the columns of the table. In this case, the syntax is as follows:
INSERT INTO nom_de_la_table
VALUES (valeur1, valeur2, valeur3, …, valeurN);
postgreSql
In any case, you must store the different values in the right order. They are inserted in the different columns from left to right.
Example of the PostgreSql command INSERT INTO
The best way to illustrate how postgreSql INSERT INTO works in practice is to give a concrete example. To do this, we create a table called « customer list » with Postgresql CREATE TABLE. This contains four columns entitled « ID », « Name », « City » and « Address ». Here is what the corresponding code looks like:
CREATE TABLE liste_des_clients (
ID SERIAL PRIMARY KEY,
Nom VARCHAR(50) NOT NULL,
Ville VARCHAR(50),
Adresse VARCHAR(255)
);
postgreSql
To insert a line, we use PostgreSql INSERT ::
INSERT INTO liste_des_clients (ID, Nom, Ville, Adresse)
VALUES (1, 'Madiot', 'Lyon', '1, rue du Commerce');
postgreSql
In the following example, we do not know the address of a client and leave this field empty during the entry. He then receives the default value defined in the table. If no value has been defined, the value is NULL. Here is the code:
INSERT INTO liste_des_clients (ID, NOM, VILLE)
VALUES (2, 'Wirth', 'Toulouse');
postgreSql
Insert several lines at the same time with PostgreSql INSERT
It is also possible to add Several lines at the same time In PostgreSql with INSERT INTO. In the following code, we insert two additional customers:
INSERT INTO liste_des_clients (ID, Nom, Ville, Adresse)
VALUES
(3, 'Bourrat', 'Strasbourg', '17, rue du Bac'),
(4, 'Sambat', 'Montpellier', '73, place de la République');
postgreSql
The lines are put in parentheses and separated by commas.
Advice
If you want to delete the contents of a line, you can do it with the postgreSql command DELETE.

