From: 王学敏 <wang1352083@163.com>
To: Matheus de Oliveira <matioli.matheus@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: pg import text data to not null table comma error but semicolon right
Date: Fri, 27 Jun 2014 14:41:20 +0800 (CST)
Message-ID: <494c8a89.86fe.146dc0e8ec1.Coremail.wang1352083@163.com> (raw)
In-Reply-To: <CAJghg4KA_XBLgo8nEV+pgZrTaNxbZyX2KL0xcKGHRKVcEc8CBw@mail.gmail.com>
References: <21c10616.195a8.146d82287df.Coremail.wang1352083@163.com>
<CAJghg4KA_XBLgo8nEV+pgZrTaNxbZyX2KL0xcKGHRKVcEc8CBw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
tks
if import data with csv there error
like:
\copy t(d1,d2,d3) from 'comma.csv' with delimiter ',' csv ;
ERROR: null value in column "d2" violates not-null constraint
DETAIL: Failing row contains (e, null, g).
CONTEXT: COPY t, line 2: "e,,g"
and there right
\copy t(d1,d2,d3) from 'comma.csv' with delimiter ',' ;
demo_pg94=>
At 2014-06-26 08:57:32, "Matheus de Oliveira" <matioli.matheus@gmail.com> wrote:
On Thu, Jun 26, 2014 at 9:24 AM, 王学敏 <wang1352083@163.com> wrote:
\copy t(d1,d2,d3) from 'comma.text' with delimiter ',';
ERROR: missing data for column "d2"
CONTEXT: COPY t, line 1: "a;b;c"
This error happens because the line uses semicolon (";") as delimiter and you used comma (",") on COPY command, so PG thinks "a;b;c" is all value for column d1, and so there is no values for d2 and d3.
Looks like you are using a file different from the one you showed.
\copy t(d1,d2,d3) from 'semicolon.text' with delimiter ';' ;
--no error
cat semicolon.text
a;b;c
e;;f
That should be fine indeed. On the second line d2 will be imported as empty string, not NULL, hence no error.
If you wanted this to be considered NULL, you should be using CSV format, like this:
\copy t(d1,d2,d3) FROM 'semicolon.text' WITH CSV DELIMITER ';' ;
And that would give the error you probably expect:
ERROR: 23502: null value in column "d2" violates not-null constraint
DETAIL: Failing row contains (e, null, f).
CONTEXT: COPY t, line 2: "e;;f"
So. No bug here.
Regards,
--
Matheus de Oliveira
Analista de Banco de Dados
Dextra Sistemas - MPS.Br nível F!
www.dextra.com.br/postgres
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: wang1352083@163.com, matioli.matheus@gmail.com
Subject: Re: pg import text data to not null table comma error but semicolon right
In-Reply-To: <494c8a89.86fe.146dc0e8ec1.Coremail.wang1352083@163.com>
References: <21c10616.195a8.146d82287df.Coremail.wang1352083@163.com> <CAJghg4KA_XBLgo8nEV+pgZrTaNxbZyX2KL0xcKGHRKVcEc8CBw@mail.gmail.com> <494c8a89.86fe.146dc0e8ec1.Coremail.wang1352083@163.com>
* 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