Files
Letters/xinhan/schema.md
T

44 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Xinhan 数据表结构说明
本文档提供针对 xinhan 表的 SQL 创建语句与示例查询。注意:以下 SQL 仅用于创建结构;本任务仅生成 MD 文档,不执行 SQL。
## 数据字段与含义
- recipient: 收件人,为文本类型,必填
- content: 内容物,文本型,可包含多行描述
- sent_date: 寄出日期,时间戳(timestamptz/ TIMESTAMP),必填
- destination: 寄达地,文本
- arrival_date: 寄达日期,时间戳
## 建表 SQLPostgreSQLSupabase/ Postgres 兼容)
```sql
CREATE TABLE xinhan (
id SERIAL PRIMARY KEY,
recipient TEXT NOT NULL,
content TEXT,
sent_date TIMESTAMP WITHOUT TIME ZONE NOT NULL,
destination TEXT,
arrival_date TIMESTAMP WITHOUT TIME ZONE
);
-- 索引,提升按收件人、寄出日期/寄达日期的查询性能
CREATE INDEX IF NOT EXISTS idx_xinhan_recipient ON xinhan (recipient);
CREATE INDEX IF NOT EXISTS idx_xinhan_sent_date ON xinhan (sent_date);
CREATE INDEX IF NOT EXISTS idx_xinhan_arrival_date ON xinhan (arrival_date);
```
## 示例查询
```sql
-- 查询某个收件人相关信函的简单示例
SELECT * FROM xinhan
WHERE recipient ILIKE '%张三%'
ORDER BY sent_date DESC
LIMIT 100;
-- 根据日期范围查询示例
SELECT * FROM xinhan
WHERE sent_date BETWEEN '2024-01-01' AND '2026-12-31'
ORDER BY sent_date DESC;
```
> 说明:此文件仅用于记录数据库结构与查询示例,实际部署请在你的数据库实例中执行上述 SQL。