RE: COPY Question

From: "Culberson, Philip" <philip(dot)culberson(at)dat(dot)com>
To: "'Samuel A(dot) Mullen'" <smullen(at)oppunl(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: RE: COPY Question
Date: 2000-04-21 20:37:24
Message-ID: A95EFC3B707BD311986C00A0C9E95B6A9DE6BD@datmail03.dat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Since triggers ARE fired by the COPY command, another possibility is the use
of a temporary trigger to simulate the functionality of DEFAULT.

Just change the name of the sequence and the table in the example below.
Once you are done with your copy, simply DROP TRIGGER fake_sequence ON foo;

Caveat Emptor: I have not exhaustively tested this, although it did work
with a small data file on my test system... I'm sure you will want to run
this when NO ONE else is using the database, if such a time exists ;^)

CREATE FUNCTION fake_sequence() RETURNS OPAQUE AS '
BEGIN
NEW.dup_id = NEXTVAL(''foo_dup_id_seq'');
RETURN NEW;
END;' LANGUAGE 'plpgsql';

CREATE TRIGGER fake_sequence
BEFORE INSERT ON foo FOR EACH ROW EXECUTE PROCEDURE fake_sequence();

-----Original Message-----
From: Samuel A. Mullen [mailto:smullen(at)oppunl(dot)com]
Sent: Friday, April 21, 2000 8:37 AM
To: pgsql-general
Subject: Re: [GENERAL] COPY Question

Disregard this. I went with a temp table solution.

Thanks,

Sam

Bruce Momjian wrote:
>
> > As you can see I'm delimiting the fields with a '|' character. You will
> > also notice that there is no field 1. I was hoping that I could leave
> > that blank and the sequence automatically fill in the PKEY. Does this
> > not work?
>
> DEFAULTS are not activated by COPY.
> --
> Bruce Momjian | http://www.op.net/~candle
> pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
> + If your life is a hard drive, | 830 Blythe Avenue
> + Christ can be your backup. | Drexel Hill, Pennsylvania 19026

--
_____________________
/ Samuel A. Mullen \
| Programmer Analyst |_______________________________________________
| Opportunities Unl. | My soul shall be satisfied as [with] marrow \
\_____________________/| and fatness; and my mouth shall praise [thee] |
| with joyful lips: |
| Psalms 63:4 |
\_______________________________________________/

Browse pgsql-general by date

  From Date Subject
Next Message Manuel Lemos 2000-04-21 23:02:00 Re: Connecting website with SQL-database.....
Previous Message swalker 2000-04-21 20:10:11 Re: How to get the size of a large object?