|
|
19 godzin temu | |
|---|---|---|
| .. | ||
| DF_DO202601130001_workflow.json | 19 godzin temu | |
| README_import_product_inventory.md | 6 dni temu | |
| import_product_inventory_workflow.json | 19 godzin temu | |
这个 n8n 工作流用于从远程 PostgreSQL 数据库导入产品库存数据到本地数据资源表 test_product_inventory。
CREATE TABLE test_product_inventory (
id serial COMMENT '编号',
sku varchar(50) COMMENT '商品货号',
category varchar(100) COMMENT '类别',
brand varchar(100) COMMENT '品牌',
supplier varchar(200) COMMENT '供应商',
warehouse varchar(100) COMMENT '仓库',
current_stock integer COMMENT '当前库存',
safety_stock integer COMMENT '安全库存',
max_stock integer COMMENT '最大库存',
unit_cost numeric(10, 2) COMMENT '单位成本',
selling_price numeric(10, 2) COMMENT '销售价格',
stock_status varchar(50) COMMENT '库存状态',
last_inbound_date date COMMENT '最近入库日期',
last_outbound_date date COMMENT '最近出库日期',
inbound_quantity_30d integer COMMENT '30天入库数量',
outbound_quantity_30d integer COMMENT '30天出库数量',
turnover_rate numeric(5, 2) COMMENT '周转率',
is_active boolean COMMENT '是否有效',
created_at timestamp COMMENT '创建时间',
updated_at timestamp COMMENT '更新时间',
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '数据创建时间'
);
COMMENT ON TABLE test_product_inventory IS '产品库存表';
import_resource_data.pyimport_product_inventory_workflow.json⚠️ 重要: 在运行工作流之前,必须配置数据库密码!
YOUR_PASSWORD_HERE 占位符示例:
python "g:\code-lab\DataOps-platform-new\datafactory\scripts\import_resource_data.py" --source-config '{"type":"postgresql","host":"192.168.3.143","port":5432,"database":"dataops","username":"postgres","password":"your_actual_password","table_name":"test_product_inventory"}' --target-table test_product_inventory --update-mode append
工作流执行后,你可以在 n8n 界面中查看:
导入完成后,可以通过以下 SQL 查询验证数据:
-- 查看导入的数据总数
SELECT COUNT(*) FROM test_product_inventory;
-- 查看最近导入的数据
SELECT * FROM test_product_inventory
ORDER BY create_time DESC
LIMIT 10;
-- 按类别统计库存
SELECT category, COUNT(*) as count, SUM(current_stock) as total_stock
FROM test_product_inventory
GROUP BY category;
解决方案:
解决方案:
解决方案:
test_product_inventory 表append (追加模式),新数据会追加到目标表,不会删除现有数据--limit 参数限制每次导入的数据量如需只导入特定条件的数据,可以在源配置中添加 where_clause:
{
"type": "postgresql",
"host": "192.168.3.143",
"port": 5432,
"database": "dataops",
"username": "postgres",
"password": "your_password",
"table_name": "test_product_inventory",
"where_clause": "created_at >= '2026-01-01' AND is_active = true"
}
如需按特定字段排序,可以添加 order_by:
{
"type": "postgresql",
"host": "192.168.3.143",
"port": 5432,
"database": "dataops",
"username": "postgres",
"password": "your_password",
"table_name": "test_product_inventory",
"order_by": "created_at DESC"
}
如需限制每次导入的数据量,可以添加 --limit 参数:
--limit 1000
如有问题,请联系:
最后更新: 2026-01-07