0

我有一个大型查询可以加密/解密 PostgreSQL 中的一个表。我向这个查询添加了一个新的条件,它现在抛出一个错误。原始查询根据日期和内部连接相关性检索所有记录(来自 tblSessions 的所有满足条件的记录)。

更新后的查询仅从 tblSessions 中检索parent_session_id不为空的记录(结果中省略了来自 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 窗口中,运行第二个查询给我以下错误:

错误:函数解密(整数,“未知”,“未知”)不存在 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')

我理解错误消息,但这不可能是实际问题,因为查询的所有添加都已正确解码。我错过了一些明显的东西吗?

4

1 回答 1

1

问题提到了parent_session_id类型INTEGER,但它在下面的代码段中作为第一个参数传递decrypt,与其他似乎只传递bytea字段的代码不同。

decrypt(s.parent_session_id, '####salt####', '###encryption mode###')

这可能会引发提到的错误,因为没有decrypt将整数作为第一个参数的味道(从错误消息中,可以用\df decryptin确认psql

您确定这些会话 ID 已加密吗?

于 2013-01-21T20:36:00.490 回答