test.py 679 B

12345678910111213141516171819202122232425262728293031
  1. # 连接数据库
  2. import psycopg2
  3. from psycopg2.extras import DictCursor
  4. import logging
  5. # 配置日志
  6. logging.basicConfig(level=logging.INFO)
  7. logger = logging.getLogger(__name__)
  8. conn = psycopg2.connect(
  9. dbname="real3d",
  10. user="postgres",
  11. password="postgis",
  12. host="192.168.1.177",
  13. port="5432"
  14. )
  15. def getDiffEwkt():
  16. with conn.cursor(cursor_factory=DictCursor) as cur:
  17. sql = f"""SELECT * FROM base."t_fzss_fzxz" limit 1;"""
  18. complete_sql = cur.mogrify(sql, ).decode('utf-8')
  19. logger.info(f"Executing SQL: {complete_sql}")
  20. cur.execute(sql, )
  21. res = cur.fetchone()
  22. print(res)
  23. return res[0]
  24. getDiffEwkt()