Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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');
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...



Neil Conway <neilconway(at)rogers(dot)com>

Attachment: copy-def-value-2.patch
Description: application/octet-stream (22.2 KB)


pgsql-patches by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group