COPY and default values

From: Neil Conway <nconway(at)klamath(dot)dyndns(dot)org>
To: PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: COPY and default values
Date: 2002-05-27 19:13:12
Message-ID: 20020527151312.695c88be.nconway@klamath.dyndns.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

The attached patch changes COPY so that if no value for an attribute
is specified, the default value for the attribute (or the attribute's
type) will be assigned, rather than NULL.

I'll write some regression tests and update the docs later. Also,
there's a possible optimization that I didn't implement: if the
default value Node is a 'Const', we can safely evaluate and store
the default value once for the lifetime of the COPY, rather than
every time that it is needed. However, Const Nodes are evaluated
very quickly by ExecEvalExpr(), so I'm not sure if it's worth
worrying about...

There's one major problem with the patch, which I haven't been
able to fix: when there are multiple rows of data which require
default values, the COPY fails:

nconway=# create table test (a int, b text default 'def value');
CREATE TABLE
nconway=# copy test from stdin;
>> 5
>> \.
nconway=# copy test from stdin;
>> 10
>> 15
>> \.
ERROR: copy: line 2, Memory exhausted in AllocSetAlloc(1065320379)

I think I've mismanaged the memory contexts involved somehow, but
I'm not sure what the problem is. Any help would be appreciated...

Cheers,

Neil

--
Neil Conway <neilconway(at)rogers(dot)com>
PGP Key ID: DB3C29FC

Attachment Content-Type Size
copy-def-value-2.patch application/octet-stream 22.2 KB

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2002-05-27 20:18:48 Re: revised sample SRF C function; proposed SRF API
Previous Message Tom Lane 2002-05-27 16:09:55 Re: small dblink patch