Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

290
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda