How to use COPY in a function ?

Поиск
Список
Период
Сортировка
От Roelof Sondaar
Тема How to use COPY in a function ?
Дата
Msg-id 3BF3EB9F.E4C5B46E@wmdata.nl
обсуждение исходный текст
Ответы Re: How to use COPY in a function ?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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.ipaddressLOOP
 
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';


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

Предыдущее
От:
Дата:
Сообщение: Re: Foreign Key Constraint Deletion Order
Следующее
От: "Jack Gao"
Дата:
Сообщение: Re: Is this a bug?