Automate copy - Postgres 9.2
От | Patrick B |
---|---|
Тема | Automate copy - Postgres 9.2 |
Дата | |
Msg-id | CAJNY3itCAKH2D2mZ7F9ScJ8qV3KefLrdUnDttjaa6HvNgxEW=g@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: Automate copy - Postgres 9.2
Re: Automate copy - Postgres 9.2 |
Список | pgsql-general |
Hi guys,
Can anybody give me a help here please?
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 $$declarecrtRow record;beginFOR crtRow in execute 'select account_id from backup_table WHERE migrated = 1 AND account_id = '|| $1LOOPCOPY(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
В списке pgsql-general по дате отправления: