我正在将一些使用MySQL的工具转换为PostgreSQL。在此过程中,我遇到了许多问题,但是大多数都已找到解决方法。唯一出现问题的是HEX()
和UNHEX()
函数。我尝试了encode(%s, 'hex')
和decode(%s, 'hex')
,虽然不再出现错误,但似乎并没有达到预期效果。请问是否有人知道在PostgreSQL中相应的函数是什么?
这里是旧的MySQL查询:
SELECT HEX(test_table.hash),
title,
user,
reason,
description,
url,
performed,
comment,
authenticated,
status
FROM alerts
JOIN user_responses ON test_table.hash = user_responses.hash
JOIN test_status ON test_table.hash = test_status.hash
WHERE status = %s
这是我用PostgreSQL格式更新后的查询:
SELECT encode(test_table.hash, 'hex') as hash,
title,
user,
reason,
description,
url,
performed,
comment,
authenticated,
status
FROM test_table
JOIN user_responses ON test_table.hash = user_responses.hash
JOIN test_status ON test_table.hash = test_status.hash
WHERE status = %s
谢谢!