Re: NEED HELP COPY TO DYNAMIC OUTPUT FILE

From: "Yogi Dwianandono Rizkiadi" <gie05tech(at)yahoo(dot)co(dot)id>
To: "'Pavel Stehule'" <pavel(dot)stehule(at)gmail(dot)com>, "'Tom Lane'" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: NEED HELP COPY TO DYNAMIC OUTPUT FILE
Date: 2009-08-31 05:47:34
Message-ID: 002d01ca29fe$8a4af280$9ee0d780$@co.id
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)postgresql(dot)org [mailto:pgsql-sql-owner(at)postgresql(dot)org] On Behalf Of Pavel Stehule
Sent: 30 Agustus 2009 22:56
To: Tom Lane
Cc: Yogi Rizkiadi; pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] NEED HELP COPY TO DYNAMIC OUTPUT FILE

2009/8/30 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> Pavel Stehule <pavel(dot)stehule(at)gmail(dot)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(at)postgresql(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message bilal ghayyad 2009-09-01 00:53:23 PostgreSQL Function: how to know the number of the returned results of the Query
Previous Message db1981 2009-08-30 19:15:48 Searching for byte values within a bytea field