From 488d9b57f1de581a656642d39f8cd388fe5cbe31 Mon Sep 17 00:00:00 2001 From: Himmel Date: Fri, 30 May 2025 17:25:47 +0800 Subject: [PATCH] Update INSERT command examples in both CN and EN versions - Add new table 'new_products' to demonstrate more complex INSERT examples - Include INSERT commands for the new table with sample data - Update the example of inserting query results to use a specific date --- CN/modules/ROOT/pages/v4.4/8.adoc | 14 +++++++++++++- EN/modules/ROOT/pages/v4.4/8.adoc | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CN/modules/ROOT/pages/v4.4/8.adoc b/CN/modules/ROOT/pages/v4.4/8.adoc index 033f1e6..57327c1 100644 --- a/CN/modules/ROOT/pages/v4.4/8.adoc +++ b/CN/modules/ROOT/pages/v4.4/8.adoc @@ -149,6 +149,13 @@ CREATE TABLE products ( name text, price numeric ); + +CREATE TABLE new_products ( + product_no int , + name varchar(255), + price DECIMAL(10, 2), + release_date DATE +); ``` 一个插入一行的命令将是: @@ -191,6 +198,11 @@ INSERT INTO products (product_no, name, price) VALUES (1, 'Cheese', 9.99), (2, 'Bread', 1.99), (3, 'Milk', 2.99); + +INSERT INTO new_products (product_no, name, price, release_date) VALUES + (1, 'A', 100.00, '2025-05-29'), + (2, 'B', 150.50, '2024-11-20'), + (3, 'C', 200.75, '2025-05-29'); ``` 也可以插入查询的结果(可能没有行、一行或多行): @@ -198,7 +210,7 @@ INSERT INTO products (product_no, name, price) VALUES ``` INSERT INTO products (product_no, name, price) SELECT product_no, name, price FROM new_products - WHERE release_date = 'today'; + WHERE release_date = '2025-05-29'; ``` 这提供了用于计算要插入的行的SQL查询机制( http://www.postgresql.org/docs/17/queries.html[第 7 章])的全部功能。 diff --git a/EN/modules/ROOT/pages/v4.4/8.adoc b/EN/modules/ROOT/pages/v4.4/8.adoc index 1257fc5..7e96750 100644 --- a/EN/modules/ROOT/pages/v4.4/8.adoc +++ b/EN/modules/ROOT/pages/v4.4/8.adoc @@ -155,6 +155,13 @@ CREATE TABLE products ( name text, price numeric ); + +CREATE TABLE new_products ( + product_no int , + name varchar(255), + price DECIMAL(10, 2), + release_date DATE +); ``` An example command to insert a row would be: @@ -197,6 +204,11 @@ INSERT INTO products (product_no, name, price) VALUES (1, 'Cheese', 9.99), (2, 'Bread', 1.99), (3, 'Milk', 2.99); + +INSERT INTO new_products (product_no, name, price, release_date) VALUES + (1, 'A', 100.00, '2025-05-29'), + (2, 'B', 150.50, '2024-11-20'), + (3, 'C', 200.75, '2025-05-29'); ``` It is also possible to insert the result of a query (which might be no rows, one row, or many rows): @@ -204,7 +216,7 @@ It is also possible to insert the result of a query (which might be no rows, one ``` INSERT INTO products (product_no, name, price) SELECT product_no, name, price FROM new_products - WHERE release_date = 'today'; + WHERE release_date = '2025-05-29'; ``` This provides the full power of the SQL query mechanism for computing the rows to be inserted.