Postgresql

更新大整數來自 SELECT 的列

  • January 25, 2017

我必須更新一個bigint[]名為permissao_ver.

範例值:'{1,2,3,4,5,11,44,56,75,11}'.

虛擬碼:

UPDATE callcenter.pausa  
SET permissao_ver = '{"(SELECT cod_grupo FROM crm.usuariosgrupos
                       WHERE habilitar = 1)"}'::bigint[] 
WHERE habilitado = 1 AND permissao_ver is null

我需要獲取上述選擇將以與bigint[]列匹配的格式返回的程式碼。喜歡:'{XX, XX, XX, X, XX, X}'

使用array

UPDATE callcenter.pausa  
SET permissao_ver = array(SELECT cod_grupo 
                         FROM crm.usuariosgrupos
                         WHERE habilitar = 1)
WHERE habilitado = 1 
 AND permissao_ver is null

另一種選擇

UPDATE callcenter.pausa  
SET permissao_ver = (SELECT array_agg(cod_grupo) 
                    FROM crm.usuariosgrupos
                    WHERE habilitar = 1)
WHERE habilitado = 1 
 AND permissao_ver is null

引用自:https://dba.stackexchange.com/questions/162250