pgsql批量插入数据
时间: 2023-12-08 11:03:02 浏览: 98
批量插入数据库
4星 · 用户满意度95%
pgsql批量插入数据可以使用INSERT INTO ... SELECT语法,将查询的结果插入表中。具体操作步骤如下:
1.创建目标表,例如:
```sql
CREATE TABLE user_A(
id int primary key,
name varchar,
order_date date,
total_amount numeric(10,2)
);
```
2.编写查询语句,例如:
```sql
SELECT c.customer_id, c.customer_name, o.order_date, o.total_amount
FROM orders o, products p, customers c
WHERE o.customer_id = c.customer_id AND o.order_id = p.product_id AND total_amount > 100;
```
3.将查询结果插入目标表中,例如:
```sql
INSERT INTO user_A(id, name, order_date, total_amount)
SELECT c.customer_id, c.customer_name, o.order_date, o.total_amount
FROM orders o, products p, customers c
WHERE o.customer_id = c.customer_id AND o.order_id = p.product_id AND total_amount > 100;
```
这样就可以将查询结果批量插入到目标表中了。
阅读全文