PostgreSQL----INSERT

Source: Internet
Author: User

Insert is writing data to the table, each INSERT statement can write one piece of data, or it can write multiple data. You can also use additional query result sets in insert to write query results to a table.

Test table

Test=createtableintvarchar(+)); CREATE TABLE

Example 1. Single Record insert

Test=insert intovalues (1,'test'); INSERT 0 1

Example 2. Multiple record inserts

The difference between an insert and a single record is that each value is separated by a comma, and the last value is followed by a semicolon.

Test=insertinto Values (2,'test'), (3 ,'sd'), (4,'ff'); INSERT 0 3

Example 3. Query Results Insert

Generate_series (1,10) generates 1 to 10 consecutive 10 numbers, concat parameters are strung together to form a new string, and the arguments can be many.
Test=#Insert  intoTbl_insert (A, B)SelectId,concat (ID,'Test') fromGenerate_series (1,Ten) ID;INSERT 0 TenTest=#Select *  fromTbl_insert; a|b----+--------  1 |Test2 |Test3 |SD4 |FF1 |1test2 |2test3 |3test4 |4test5 |5test6 |6test7 |7test8 |8test9 |9testTen |10test ( -Rows

Example 4. SELECT into creates a new table and writes the query results to the table, but fails if the table already exists.

Test=Select* into Tbl_insert1 from    tbl_insert; SELECT  - Test = Select *  into Tbl_insert1 from    Tbl_insert; ERROR:  exists

PostgreSQL----INSERT

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.