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  (John R Pierce <pierce@hogranch.com>)
Re: Automate copy - Postgres 9.2  (Adrian Klaver <adrian.klaver@aklaver.com>)
Список 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?

В списке pgsql-general по дате отправления:

Предыдущее
От: Berend Tober
Дата:
Сообщение: Re: Using a VIEW as a temporary mechanism for renaming a table
Следующее
От: John R Pierce
Дата:
Сообщение: Re: Automate copy - Postgres 9.2