Trigger/copy issue

From: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
To: pgsqlnovice <pgsql-novice(at)postgresql(dot)org>
Subject: Trigger/copy issue
Date: 2005-02-04 17:25:13
Message-ID: BAAA0C26-76D1-11D9-8CA5-000D933565E8@mail.nih.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I have the following setup and data file that I want to load using copy
(8.0.0, macos). The trigger function is to "clean" the input data (see
earlier posts on the subject). However, it seems as if the trigger
function is not doing what I would have thought. I want it to replace
'-' in the data in certain columns with NULLs. Here is the SQL and a
few lines of sample data (sorry, may be broken up due to issues in the
email line splits).

Thanks for any insights.

Sean

CREATE TABLE g_refseq (
g_refseq_id serial primary key,
species integer not null,
gene_id integer not null,
status VARCHAR,
nuc_acc varchar,
nuc_gi integer,
prot_acc varchar,
prot_gi integer,
chrom_acc varchar,
chrom_gi integer,
chrom_start integer,
chrom_end integer,
strand char );

create or replace function tgf_g_refseq_clean() returns trigger as $$
begin
NEW.prot_acc:=substring(NEW.prot_acc from '[A-Z][A-Z]_[0-9]*');
NEW.nuc_acc:=substring(NEW.nuc_acc from '[A-Z][A-Z]_[0-9]*');
NEW.chrom_acc:=substring(NEW.chrom_acc from '[A-Z][A-Z]_[0-9]*');
if (NEW.prot_gi='-') THEN
NEW.prot_gi:= 'NULL';
END IF;
if (NEW.nuc_gi='-') THEN
begin
raise notice 'we are here';
NEW.nuc_gi:= 'NULL';
end;
END IF;
if (NEW.chrom_gi='-') THEN
NEW.chrom_gi:= 'NULL';
END IF;
if (NEW.chrom_start='-') THEN
NEW.chrom_start = 'NULL';
END IF;
if (NEW.chrom_end='-') THEN
NEW.chrom_end = 'NULL';
END IF;
return NEW;
end;
$$ language plpgsql;

create trigger tg_g_refseq_clean before insert or update on g_refseq
for each row execute procedure tgf_g_refseq_clean();

DATA BELOW

9 1246500 Provisional - - NP_047184.1 10954455 NC_001911.1 10954454 348
1190 -
9 1246501 Provisional - - NP_047186.1 10954457 NC_001911.1 10954454
2157 2912 +
9 1246502 Provisional - - NP_047187.1 10954458 NC_001911.1 10954454
3040 4590 +
9 1246503 Provisional - - NP_047188.1 10954459 NC_001911.1 10954454
4623 5714 +
9 1246504 Provisional - - NP_047189.1 10954460 NC_001911.1 10954454
5717 7117 +
9 1246505 Provisional - - NP_047190.1 10954461 NC_001911.1 10954454
7141 7767 +
9 1246509 Provisional - - NP_858065.1 31982990 NC_004843.1 31982989 8
457 +
9 1246510 Provisional - - NP_858066.1 31982991 NC_004843.1 31982989 607
1449 +
139 1343044 NA - - - - NC_004971.1 32455274 160 417 +
139 1343045 Provisional - - NP_862625.1 32455275 NC_004971.1 32455274
414 650 +

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2005-02-04 18:26:39 Re: Trigger/copy issue
Previous Message Arthur van Dorp 2005-02-04 15:34:56 Re: [despammed] Re: Using a preprocessor for constants in