PostgreSQL database insert INTO command use method

Source: Internet
Author: User
Tags postgresql

First look at the example

INSERT INTO crud_conf (
Created_date, Stat_date, Name, description, options, TABLE_NAME,
Grid_show, C_type, seq, Sql_parm, Is_search, Is_delete, user_id)

SELECT created_date, Stat_date, Name, description, options, TABLE_NAME,
Grid_show, C_type, seq, Sql_parm, Is_search, Is_delete, user_id
From Crud_conf_old;

I can see it, no, no, look down.

Grammar
The basic syntax for the INSERT into statement is shown below.

INSERT into table_name (column1, Column2, Column3,... ColumnN)]
VALUES (value1, value2, value3,... Valuen);


Here Column1, Column2,... ColumnN is the name of the column in the table where the data is to be inserted.

You can list the destination column names in any order. The VALUES clause or query value is left to right with an explicit or implicit column list.

If you want to add values for all columns in a table, you may not need to specify the column (secondary) name in the SQL query. But make sure that the table is in the order of the column values in the same order. SQL INSERT into syntax is as follows: Www.111cn.net

INSERT into table_name VALUES (VALUE1,VALUE2,VALUE3,... Valuen);
OUTPUT


The following table summarizes the output messages and their implications:

Output message Description
INSERT OID 1 message returned if only one row is inserted. The OID is the numeric OID of the inserted row.
INSERT 0 # message returned if more than one rows were inserted. # is the number of rows inserted.
instance
Create a table company in the database TestDB is as follows:

CREATE TABLE Company (
ID INT PRIMARY KEY not NULL,
NAME TEXT not NULL,
Age INT is not NULL,
Address CHAR (50),
SALARY Real,
Join_date DATE
);


in the following example, insert a row to the company table:

INSERT into Company (id,name,age,address,salary,join_date) VALUES (1, ' Paul ',, ' California ', 20000.00, ' 2001-07-13 ');


The following example inserts a row; The salary column is omitted here, so it will have a default value:

INSERT into Company (id,name,age,address,join_date) VALUES (2, ' Allen ', ' Texas ', ' 2007-12-13 ');


The following example uses the Address column instead of the default clause that specifies a value:

INSERT into Company (id,name,age,address,salary,join_date) VALUES (3, ' Teddy ', N, ' Norway ', 20000.00, DEFAULT);


The following example uses multiple lines of multiple-line value syntax:

INSERT into Company (id,name,age,address,salary,join_date) VALUES (4, ' Mark ', ' rich-mond ', ' 65000.00 ', ' 2007-12-13 '), (5, ' David ', ', ' Texas ', 85000.00, ' 2007-12-13 ');


Company table, all of the statements above will create the following records. The next chapter will learn how to display all of these records from a single table.

ID NAME Age Address SALARY join_date
----      ----------  -----      ----------  -------   --------
1 Paul California 20000.0 2001-07-13
2 Allen Texas 2007-12-13
3 Teddy Norway 20000.0
4 Mark Rich-mond 65000.0 2007-12-13
5 David Texas 85000.0 2007-12-13

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.