Re: Automate copy - Postgres 9.2

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Patrick B <patrickbakerbr(at)gmail(dot)com>, rob stone <floriparob(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, John R Pierce <pierce(at)hogranch(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Automate copy - Postgres 9.2
Date: 2016-06-13 21:47:42
Message-ID: 151e3fae-00f2-de67-ca8f-2578558bd0c6@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 06/13/2016 02:42 PM, Patrick B wrote:
> Hi guys,
>
> I created this function:
>
> CREATE or REPLACE FUNCTION function(account_id integer)
>
> RETURNS void AS $$
>
> begin
>
> execute 'COPY
>
> (
>
> SELECT * FROM backup_table WHERE account_id = ' ||
> account_id || 'AND status = 1
>
> )
>
> TO ''/var/lib/pgsql/'||account_id||'.sql''';
>
> end
>
> $$ language 'plpgsql';
>
>
>
> The function works fine.. but is not what I need, actually.
> The function above works by calling it specifying the account_id. For
> example:
>
> You want to copy ( backup ) for the account_id number 63742:
>
> select function(63742);
>
>
> *What I need is:*
>
> When calling the function, I have to specify the limit of account_ids to
> be copied. For example:
> To perform the commands in the function to 40 different account_ids:
>
> select function (40);
>
>
>
> How can I do that? I can't...

I believe this has been asked and answered, namely there needs to be
further information on how you want to determine the account ids to be
selected.

>
> Cheers
> Patrick

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Patrick B 2016-06-14 01:33:07 Re: Automate copy - Postgres 9.2
Previous Message Patrick B 2016-06-13 21:42:06 Re: Automate copy - Postgres 9.2