How to use COPY in a function ?

From: Roelof Sondaar <roelof(dot)sondaar(at)wmdata(dot)nl>
To: PostgreSQL SQL list <pgsql-sql(at)postgresql(dot)org>
Subject: How to use COPY in a function ?
Date: 2001-11-15 16:21:51
Message-ID: 3BF3EB9F.E4C5B46E@wmdata.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,

I tried to use COPY in a function.
It gives the following message: copyObject: don't know how to copy 610.
As I understand from the documentation COPY is not supported in a
function.

Does anyone a solution to do this in a function ?
Or can anyone give me a hint where to find it ?

I added the code at the bottom.

Thanks,

Roelof Sondaar
WM-data Zwolle B.V.

CREATE FUNCTION dnsdhcp_db_header (text)
RETURNS boolean AS '
/* This function create all the DNS db tables for the local networks */
/* It needs one parameter which is the directory where the tables */
/* should be created */
DECLARE
directory ALIAS FOR $1;
networks record;
table text;
servers record;
data record;
BEGIN
/**** For each network record create a db file ****/
/* We do this only for the local networks (location = l) */
/* The remote networks (location = r) are for slave use only */
FOR networks IN SELECT * FROM network WHERE location = ''l'' LOOP
RAISE NOTICE ''a: %'', networks.id;
/* create db.<domain> */
IF position(''n'' IN networks.use) > 0 THEN
/* Cleanup export table */
DELETE FROM export;

INSERT INTO export VALUES(''$'' || networks.ttl);
INSERT INTO export VALUES(''; Created on : '' ||
timestamp(''now''));
INSERT INTO export VALUES(''@ IN SOA '' || networks.domain
|| '' '' || networks.email || ''. ('');
INSERT INTO export VALUES('' '' || text(networks.serial)
|| '' ; Serial'');
INSERT INTO export VALUES('' '' || networks.refresh || ''
; Refresh'');
INSERT INTO export VALUES('' '' || networks.retry || ''
; Retry'');
INSERT INTO export VALUES('' '' || networks.expire || ''
; Expire'');
INSERT INTO export VALUES('' '' || networks.cachettl ||
'' ) ; Negative caching TTL'');

/* Name servers */
FOR servers IN SELECT * FROM server_dns
WHERE ipaddress_network = networks.ipaddress LOOP
RAISE NOTICE ''b: %'', servers.name;
INSERT INTO export VALUES('' IN NS '' ||
servers.name || ''.'');
END LOOP;

/* Copy the table to the given location */
RAISE NOTICE ''c: Directory: %'', $1;
table:= ''"'' || directory || ''/db.'' || networks.domain ||
''"'';
RAISE NOTICE ''d: table: %'', table;
FOR data IN SELECT * FROM export LOOP
RAISE NOTICE ''e: export: %'', data.data;
END LOOP;
COPY export TO ''/home/snlsor/carbageshshshhshsh'';

END IF;
END LOOP;

RETURN ''t'';

END;
'
LANGUAGE 'plpgsql';

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Roland Roberts 2001-11-15 16:24:47 Re: Is this a bug?
Previous Message satya pariki 2001-11-15 16:18:05 why does this query does not work??????