我有一个大型查询,用于加密/解密PostgreSQL中的一个表。我为此查询添加了一个新的条件,它现在抛出一个错误。原始查询根据日期和内部联接相关性(满足条件的tblSessions中的所有记录)检索所有记录。
更新的查询仅检索来自tblSessions的记录,其中 parent_session_id 不为null(来自tblSessions的具有子记录的任何记录都会从结果中省略)。
tblsessions (only showing fields that pertain to join conditions)
sessionid | decision_id | start_time | end_time | is_comlete | parent_session_id
---------------------------------------------------------------------------------
SERIAL | BYTEA | BYTEA | BYTEA | BYTEA | INTEGER DEFAULT 0
在Posgres的SQL窗口中,运行第二个查询会出现以下错误:
错误:函数decrypt(整数,“未知”,“未知”)不存在 SQL状态:42883 提示:没有函数匹配给定的名称和参数类型。您可能需要添加显式类型转换。
原始查询(有效):
SELECT z.conditionname, x.name AS domainname, d.decisionName,
c.firstname AS counselor_first_name, c.lastname AS counselor_last_name,
o.name AS organization_name,
encode(decrypt(s.start_time, '####salt####', '###encryption mode###'), 'escape') AS start_time,
encode(decrypt(s.end_time, '####salt####', '###encryption mode###'), 'escape') AS end_time,
encode(decrypt(s.is_complete, '####salt####', '###encryption mode###'), 'escape') AS is_complete,
s.parent_session_id
FROM tblDecisions d
INNER JOIN tblSessions s ON encode(decrypt(s.decision_id, '####salt####', '###encryption mode###'), 'escape') = d.decisionid
INNER JOIN tblCounselors c ON encode(decrypt(s.counselor_ck, '####salt####', '###encryption mode###'), 'escape') = c.campuskey
INNER JOIN tblCounselor_to_organization co ON co.counselor_id = c.counselorid
INNER JOIN tblOrganizations o ON o.organizationid = co.organization_id
INNER JOIN tblDomains x ON x.domainid = d.domain_id
INNER JOIN tblConditions z ON z.conditionid = x.condition_id
AND encode(decrypt(s.start_time, '####salt####', '###encryption mode###'), 'escape') >= '2012-01-01 00:00:00'
AND encode(decrypt(s.is_complete, '####salt####', '###encryption mode###'), 'escape') = 'true'
ORDER BY encode(decrypt(s.start_time, '####salt####', '###encryption mode###'), 'escape'), encode(decrypt(s.last_name, '####salt####', '###encryption mode###'), 'escape'), encode(decrypt(s.first_name, '####salt####', '###encryption mode###'), 'escape')
修改后的查询(不起作用;下面注释添加)
SELECT z.conditionname, x.name AS domainname, d.decisionName,
c.firstname AS counselor_first_name, c.lastname AS counselor_last_name,
o.name AS organization_name,
encode(decrypt(s.start_time, '####salt####', '###encryption mode###'), 'escape') AS start_time,
encode(decrypt(s.end_time, '####salt####', '###encryption mode###'), 'escape') AS end_time,
encode(decrypt(s.is_complete, '####salt####', '###encryption mode###'), 'escape') AS is_complete,
s.parent_session_id
//////// ADDITION START
, (SELECT MAX(encode(decrypt(start_time, '####salt####', '###encryption mode###'), 'escape')) AS start_time
FROM tblSessions s2
WHERE encode(decrypt(s2.parent_session_id, '####salt####', '###encryption mode###'), 'escape') = encode(decrypt(s.parent_session_id, '####salt####', '###encryption mode###'), 'escape') )
//////// ADDITION END
FROM tblDecisions d
INNER JOIN tblSessions s ON encode(decrypt(s.decision_id, '####salt####', '###encryption mode###'), 'escape') = d.decisionid
INNER JOIN tblCounselors c ON encode(decrypt(s.counselor_ck, '####salt####', '###encryption mode###'), 'escape') = c.campuskey
INNER JOIN tblCounselor_to_organization co ON co.counselor_id = c.counselorid
INNER JOIN tblOrganizations o ON o.organizationid = co.organization_id
INNER JOIN tblDomains x ON x.domainid = d.domain_id
INNER JOIN tblConditions z ON z.conditionid = x.condition_id
AND encode(decrypt(s.start_time, '####salt####', '###encryption mode###'), 'escape') >= '2012-01-01 00:00:00'
AND encode(decrypt(s.is_complete, '####salt####', '###encryption mode###'), 'escape') = 'true'
/////// ADDITION START
AND NOT EXISTS (
SELECT 1
FROM tblSessions s1
WHERE encode(decrypt(s1.parent_session_id, '####salt####', '###encryption mode###'), 'escape') = encode(decrypt(s.sessionid, '####salt####', '###encryption mode###'), 'escape') )
AND (
( encode(decrypt(s.parent_session_id, '####salt####', '###encryption mode###'), 'escape') IS NULL) OR
( encode(decrypt(s.start_time, '####salt####', '###encryption mode###'), 'escape') = (
SELECT MAX(encode(decrypt(start_time, '####salt####', '###encryption mode###'), 'escape')) AS start_time
FROM tblSessions s2
WHERE encode(decrypt(s2.parent_session_id, '####salt####', '###encryption mode###'), 'escape') = encode(decrypt(s.parent_session_id, '####salt####', '###encryption mode###'), 'escape')
)
)
)
///////// ADDITION END
ORDER BY encode(decrypt(s.start_time, '####salt####', '###encryption mode###'), 'escape'), encode(decrypt(s.last_name, '####salt####', '###encryption mode###'), 'escape'), encode(decrypt(s.first_name, '####salt####', '###encryption mode###'), 'escape')
我理解错误消息,但这不是实际问题,因为查询的所有添加都已正确解码。我错过了一些明显的东西吗?
答案 0 :(得分:1)
问题提到parent_session_id
是INTEGER
类型,但它在下面的代码段中作为decrypt
的第一个参数传递,与其他似乎仅通过的代码不同{那里有{1}}个字段。
bytea
这可能会引发上述错误,因为没有decrypt(s.parent_session_id, '####salt####', '###encryption mode###')
的味道,它将整数作为第一个参数(来自错误消息,可以通过decrypt
中的\df decrypt
确认})
您确定这些会话ID已加密吗?