Skip to content

Update INSERT command examples in both CN and EN versions #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion CN/modules/ROOT/pages/v4.4/8.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
```

一个插入一行的命令将是:
Expand Down Expand Up @@ -191,14 +198,19 @@ 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');
```

也可以插入查询的结果(可能没有行、一行或多行):

```
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 章])的全部功能。
Expand Down
14 changes: 13 additions & 1 deletion EN/modules/ROOT/pages/v4.4/8.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -197,14 +204,19 @@ 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):

```
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.
Expand Down