Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!