From: Yogi Dwianandono Rizkiadi <gie05tech@yahoo.co.id>
To: 'Pavel Stehule' <pavel.stehule@gmail.com>
To: 'Tom Lane' <tgl@sss.pgh.pa.us>
Cc: pgsql-sql@postgresql.org
Subject: Re: NEED HELP COPY TO DYNAMIC OUTPUT FILE
Date: Mon, 31 Aug 2009 12:47:34 +0700
Message-ID: <002d01ca29fe$8a4af280$9ee0d780$@co.id> (raw)
In-Reply-To: <162867790908300856u1eb20f66sfeec34a52ab6db03@mail.gmail.com>
References: <797097.88507.qm@web76214.mail.sg1.yahoo.com>
<162867790908292351g14087219r970576b9006fb91b@mail.gmail.com>
<13182.1251647634@sss.pgh.pa.us>
<162867790908300856u1eb20f66sfeec34a52ab6db03@mail.gmail.com>
Thanks guys for the quick reply, i've solve it with using EXECUTE :P
Here is my fully code :
-- Function: etiket_ho.fn_settlement(integer)
-- DROP FUNCTION etiket_ho.fn_settlement(integer);
CREATE OR REPLACE FUNCTION etiket_ho.fn_settlement(integer)
RETURNS void AS
$BODY$
DECLARE
i integer;
k integer;
STATEMENT TEXT;
v_settlement TEXT;
rec_max ALIAS FOR $1;
rec_cur CURSOR FOR
SELECT ('0220' || station_id || lpad(trans_id,5,'00000') || lpad(settlement_id,5,'00000') || flazz_card_pan || flazz_card_expired || trans_date || updated_flazz_card_balance || amount_payment || completion_code || psam_id || psam_trans_no || psam_random_no || psam_crytogram || flazz_card_cryptogram || flazz_card_trans_no || flazz_card_debit_certificate || merchant_id || terminal_id || trn || flazz_version || flazz_trac_expired || reserved) AS val_settlement FROM etiket_ho.t_settlement ORDER BY station_id, trans_id;
BEGIN
CREATE TEMPORARY TABLE log_settlement (log TEXT);
OPEN rec_cur;
i:=0; j:=0; k:=0;
LOOP
FETCH rec_cur INTO v_settlement;
EXIT WHEN NOT FOUND;
INSERT INTO log_settlement(log) VALUES(v_settlement);
IF (i=rec_max) then
STATEMENT:= 'copy log_settlement to ''/usr/proj/' || replace( current_date, '-' , '') || lpad(text(k),5,'00000') || '.txt''';
EXECUTE (STATEMENT);
TRUNCATE TABLE log_settlement;
i:=0;
ELSE
i:=i+1;
END IF;
k:=k+1;
END LOOP;
CLOSE rec_cur;
DROP TABLE log_settlement;
RETURN;
END
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION etiket_ho.fn_settlement(integer) OWNER TO postgres;
-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Pavel Stehule
Sent: 30 Agustus 2009 22:56
To: Tom Lane
Cc: Yogi Rizkiadi; pgsql-sql@postgresql.org
Subject: Re: [SQL] NEED HELP COPY TO DYNAMIC OUTPUT FILE
2009/8/30 Tom Lane <tgl@sss.pgh.pa.us>:
> Pavel Stehule <pavel.stehule@gmail.com> writes:
>> COPY in plpgsql are not allowed.
>
> I think it will work if you use an EXECUTE.
>
> regards, tom lane
>
I didn't test it.
regards
Pavel Stehule
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
__________________________________________________
Apakah Anda Yahoo!?
Lelah menerima spam? Surat Yahoo! memiliki perlindungan terbaik terhadap spam
http://id.mail.yahoo.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: gie05tech@yahoo.co.id, pavel.stehule@gmail.com, tgl@sss.pgh.pa.us
Subject: Re: NEED HELP COPY TO DYNAMIC OUTPUT FILE
In-Reply-To: <002d01ca29fe$8a4af280$9ee0d780$@co.id>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox