Enviado em 17/06/2013 - 13:01h
CREATE TABLE agenda (
chave SERIAL NOT NULL,
nome VARCHAR(100) NOT NULL,
rua VARCHAR(200),
numero INT,
telefone char(9),
PRIMARY KEY(chave)
);
-- DROP TABLE ListaInvertida;
-- CRIA TABELA listaInvertida --
CREATE TABLE ListaInvertida (
palavra VARCHAR(30),
chave INTEGER[]
);
CREATE OR REPLACE FUNCTION PopulaListaInvertida() RETURNS trigger AS $$
DECLARE
dado VARCHAR;
dado2 VARCHAR;
existe integer;
BEGIN
-- unnest CRIA UMA "TABELA" DIVIDINDO O TEXTO PELO DELIMITADOR ESPAÇO
-- LOOP PARA O NOME
FOR dado IN SELECT unnest(string_to_array(new.nome, ' ')) LOOP
existe:=0;
SELECT count(*) INTO existe FROM ListaInvertida WHERE palavra=dado;
if existe=0 then
INSERT INTO ListaInvertida (palavra, chave) VALUES (dado, new.chave);
else
UPDATE ListaInvertida SET chave=array[chave,new.chave] where palavra=dado;
end if;
END LOOP;
-- LOOP PARA O ENDEREÇO
FOR dado2 IN SELECT unnest(string_to_array(new.rua, ' ')) LOOP
existe :=0;
SELECT count(*) INTO existe FROM ListaInvertida WHERE palavra=dado;
IF existe=0 then
INSERT INTO ListaInvertida (palavra, chave) VALUES (dado2, new.chave);
ELSE
UPDATE ListaInvertida SET chave=string_to_array[chave,new.chave] where palavra=dado;
END IF;
END LOOP;
RETURN NEW;
END;
$$
LANGUAGE 'plpgsql';
O que é o THP na configuração de RAM do Linux e quando desabilitá-lo
Comparação entre os escalonadores BFQ e MQ-Deadline (acesso a disco) no Arch e Debian
Conciliando o uso da ZRAM e SWAP em disco na sua máquina
Servidor de Backup com Ubuntu Server 24.04 LTS, RAID e Duplicati (Dell PowerEdge T420)
Como unir duas coleções de ROMs preservando as versões traduzidas (sem duplicatas)
Como instalar o Telegram Desktop no Ubuntu 24.04
Overclocking Permanente para Drastic no Miyoo Mini Plus
Problemas de chaves (/usr/share/keyrings) no Debian
Converter os repositórios Debian para o novo formato com as chaves