| From: | Patrick B <patrickbakerbr(at)gmail(dot)com> | 
|---|---|
| To: | pgsql-general(at)postgresql(dot)org | 
| Subject: | Automate copy - Postgres 9.2 | 
| Date: | 2016-06-08 23:24:57 | 
| Message-ID: | CAJNY3itCAKH2D2mZ7F9ScJ8qV3KefLrdUnDttjaa6HvNgxEW=g@mail.gmail.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
Hi guys,
I need to do a file backup for each account_id.
Example:
COPY (SELECT * FROM backup_table WHERE id = 1112 AND status = 1) TO
'/var/lib/pgsql/1112.sql';
COPY (SELECT * FROM backup_table WHERE id = 1113 AND status = 1) TO
'/var/lib/pgsql/1113.sql';
COPY (SELECT * FROM backup_table WHERE id = 1114 AND status = 1) TO
'/var/lib/pgsql/1114.sql';
Can I create a PLPGSQL function to perform that?
I tried but isn't working... don't know how to determinate that:
CREATE or REPLACE FUNCTION dump(integer)
RETURNS integer AS $$
declare
crtRow record;
begin
      FOR crtRow in execute 'select account_id from backup_table WHERE
migrated = 1 AND account_id = '|| $1
LOOP
COPY
        (SELECT * FROM gorfs.WBP_4868_backup_table_BLOBS WHERE migrated = 1
AND account_id = crtRow.account_id)
TO '/var/lib/pgsql/gorfs_backup/%s.sql';
end loop;
return integer;
end
$$ language 'plpgsql';
- Each account_Id would have a file with its ID
- When calling the function, I want to specify the numbers of account_Ids I
wanna do the dump
Can anybody give me a help here please?
| From | Date | Subject | |
|---|---|---|---|
| Next Message | John R Pierce | 2016-06-09 00:13:38 | Re: Automate copy - Postgres 9.2 | 
| Previous Message | Berend Tober | 2016-06-08 22:55:14 | Re: Using a VIEW as a temporary mechanism for renaming a table |