Skip to content

Instantly share code, notes, and snippets.

create table migracao.atos_utilizados (
cartorio varchar,
protocolo_pedido varchar,
pessoa_ato varchar,
data_utilizacao varchar,
retornado varchar,
tipo_ato varchar,
nome_serventuario varchar,
inutilizado varchar,
justificativa_inutilizacao varchar,
create table migracao.lote as
select id as imovel, uuid_generate_v4() protocolo, row_number() over() as ordem
from indicador_real where livro = 'MATRICULA' and status != 'PENDENTE' and codigo in ();
with tempCodigo as (
select max(codigo) as codigo from protocolo where dominio = 'PROTOCOLO_RI' and tipo_protocolo = 'NORMAL'
)
INSERT INTO protocolo (
id, codigo, atualizacao, cadastro, cancelamento_automatico,
custas, dominio, emolumentos_busca, encerramento, entrega, entregue, exigencias, indices, legado,
@jonathanalves
jonathanalves / jsonb_remove_keys.sql
Created April 4, 2020 13:24 — forked from yyscamper/jsonb_remove_keys.sql
PostgreSQL: Remove Multiple Keys From JSONB
CREATE OR REPLACE FUNCTION jsonb_remove_keys(
jdata JSONB,
keys TEXT[]
)
RETURNS JSONB AS $$
DECLARE
result JSONB;
len INT;
target TEXT;
@jonathanalves
jonathanalves / postgres_queries_and_commands.sql
Created July 22, 2019 11:11 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@jonathanalves
jonathanalves / Gzip.java
Last active July 4, 2019 13:52
Java gzip compress/decompress string
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class Gzip {
@jonathanalves
jonathanalves / asgard.sql
Last active September 20, 2020 01:34
Querys asgard
INSERT INTO public.usuario
(id, cadastro, ativo, nome, administrador, alerta_certidao, atendente, digitalizador, financeiro, gestor, login, painel_atendimento, sangria, senha, valor_caixa, departamento_id)
VALUES(uuid_generate_v4(), CURRENT_TIMESTAMP, true, 'johnny', true, true, true, true, true, true, 'johnny', true, 0, '$2a$10$N1RmIRN4CNwuY7EIfTQhJOnJzFRmNSoa.maqWe2i3fFb6h2I2td8G', 0, 'b8e62c98-f28c-4af7-9620-90696aab89c6');
-- após criação do schema public, antes dos backups, rodar:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "unaccent";
CREATE EXTENSION IF NOT EXISTS "pg_trgm";
@jonathanalves
jonathanalves / crosstab.sql
Created April 8, 2019 22:47 — forked from romansklenar/crosstab.sql
PostgreSQL "pivot table" example using tablefunc extension
CREATE EXTENSION tablefunc;
CREATE TABLE sales(year int, month int, qty int);
INSERT INTO sales VALUES(2007, 1, 1000);
INSERT INTO sales VALUES(2007, 2, 1500);
INSERT INTO sales VALUES(2007, 7, 500);
INSERT INTO sales VALUES(2007, 11, 1500);
INSERT INTO sales VALUES(2007, 12, 2000);
INSERT INTO sales VALUES(2008, 1, 1000);
INSERT INTO sales VALUES(2009, 5, 2500);