Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

289
Visualizações
Replace a value in a query using postgresql

I have this query at postgresql:

COPY (SELECT 
"UR_16PIX_Chih"."ID_UR", 
"UR_16PIX_Chih"."IDEDOMUN15", 
"UR_16PIX_Chih"."PIX1", 
"UR_16PIX_Chih"."PIX2", 
"UR_16PIX_Chih"."PIX3", 
"UR_16PIX_Chih"."PIX4", 
"UR_16PIX_Chih"."PIX5", 
"UR_16PIX_Chih"."PIX6", 
"UR_16PIX_Chih"."PIX7", 
"UR_16PIX_Chih"."PIX8", 
"UR_16PIX_Chih"."PIX9", 
"UR_16PIX_Chih"."PIX10", 
"UR_16PIX_Chih"."PIX11", 
"UR_16PIX_Chih"."PIX12", 
"UR_16PIX_Chih"."PIX13", 
"UR_16PIX_Chih"."PIX14", 
"UR_16PIX_Chih"."PIX15", 
"UR_16PIX_Chih"."PIX16" 
FROM 
public."UR_16PIX_Chih"
WHERE 
"UR_16PIX_Chih"."IDEDOMUN15" = '08061') TO 
'/home/manager/data/Chihuahua/08061.csv' WITH CSV HEADER;

I want to know How I could replace the value '08061' with '08062', next with '08063', next with '08064', next with '08065' and so... using an automatic way. Meanwhile I'm just editing the query replacing the '08061' value with next values in pgadmin sql editor but I need a way for doing so automatically.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

One option is a PL/pgSQL function:

create or replace function c()
returns void as $c$
declare r record;
begin
    for r in
        select distinct "IDEDOMUN15" as i
        from public."UR_16PIX_Chih"
    loop
    execute format($$
        copy (
            select "ID_UR", ...
            from public."UR_16PIX_Chih"
            where "IDEDOMUN15" = '%1$s'
        ) to '/var/lib/pgsql/%1$s.csv'
    $$, r.i);
    end loop;
end;
$c$ language plpgsql;
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda