38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
"""检查数据库枚举类型"""
|
|
import asyncio
|
|
import asyncpg
|
|
|
|
|
|
async def main():
|
|
conn = await asyncpg.connect(
|
|
'postgresql://postgresql:Jchl1528@192.168.110.252:15432/hospital_performance'
|
|
)
|
|
try:
|
|
# 检查枚举类型定义
|
|
result = await conn.fetch("""
|
|
SELECT t.typname, e.enumlabel
|
|
FROM pg_type t
|
|
JOIN pg_enum e ON t.oid = e.enumtypid
|
|
WHERE t.typname = 'depttype'
|
|
ORDER BY e.enumsortorder
|
|
""")
|
|
print('DeptType 枚举值:')
|
|
for row in result:
|
|
print(f' {row["enumlabel"]} ({len(row["enumlabel"])} chars)')
|
|
|
|
# 检查 departments 表结构
|
|
result2 = await conn.fetch("""
|
|
SELECT column_name, data_type, character_maximum_length
|
|
FROM information_schema.columns
|
|
WHERE table_name = 'departments'
|
|
""")
|
|
print('\nDepartments 表结构:')
|
|
for row in result2:
|
|
print(f' {row["column_name"]}: {row["data_type"]}({row["character_maximum_length"]})')
|
|
finally:
|
|
conn.terminate()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(main())
|