pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Roelof Sondaar <roelof.sondaar@wmdata.nl>
To: PostgreSQL SQL list <pgsql-sql@postgresql.org>
Subject: How to use COPY in a function ?
Date: Thu, 15 Nov 2001 17:21:51 +0100
Message-ID: <3BF3EB9F.E4C5B46E@wmdata.nl> (raw)

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';



view thread (2+ messages)  latest in thread

Message-ID: <3BF3EB9F.E4C5B46E@wmdata.nl>
Permalink:  ../3BF3EB9F.E4C5B46E@wmdata.nl/
Also on:    postgresql.org/message-id/3BF3EB9F.E4C5B46E@wmdata.nl

 · 

reply

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: roelof.sondaar@wmdata.nl
  Subject: Re: How to use COPY in a function ?
  In-Reply-To: <3BF3EB9F.E4C5B46E@wmdata.nl>

* 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