Blank Numeric Column For INSERT

Started by Rich Shepardover 14 years ago5 messagesgeneral
Jump to latest
#1Rich Shepard
rshepard@appl-ecosys.com

I am trying to load 143K rows into a postgres-9.0.5 table from an ASCII
text file. The file consists of INSERT INTO ... statements and the VALUES
are comma delimited. One column is numeric (REAL), but ~10K rows have that
value missing, and postgres rejects the lines.

The column does not have a NOT NULL constraint.

The command line I use is 'psql -d <database_name> -f wq.sql'.

Originally I had two commas in sequence since there were no values between
them. Next I tried a space between the two commas. I tried searching in the
9.0.5 manual for 'missing values', 'missing', and another term I don't
recall but found nothing.

An example:

psql:wq.sql:8121: ERROR: syntax error at or near ","
LINE 1: ...its) VALUES (214,'SW-6','1992-11-25','oil_grease', ,'mg/L');

What is the approprate way to represent the missing column?

TIA,

Rich

#2Richard Broersma
richard.broersma@gmail.com
In reply to: Rich Shepard (#1)
Re: Blank Numeric Column For INSERT

On Wed, Nov 23, 2011 at 10:33 AM, Rich Shepard <rshepard@appl-ecosys.com> wrote:

 Originally I had two commas in sequence since there were no values between
them. Next I tried a space between the two commas. I tried searching in the
9.0.5 manual for 'missing values', 'missing', and another term I don't
recall but found nothing.

My pg.dump files show nulls as:

\N

--
Regards,
Richard Broersma Jr.

#3Rich Shepard
rshepard@appl-ecosys.com
In reply to: Richard Broersma (#2)
Re: Blank Numeric Column For INSERT

On Wed, 23 Nov 2011, Richard Broersma wrote:

My pg.dump files show nulls as:
\N

Richard,

Mine do, too. But, that's not what postgres wants to see in the .sql file.
It takes it as a newline (\n) whether quoted or not.

Thanks,

Rich

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Rich Shepard (#3)
Re: Blank Numeric Column For INSERT

Rich Shepard <rshepard@appl-ecosys.com> writes:

Mine do, too. But, that's not what postgres wants to see in the .sql file.

In an insert command, you need to either write NULL or omit the column
from the column list; empty expressions aren't syntactically correct.
(Note that the latter option actually results in inserting the column's
default, not necessarily null...)

regards, tom lane

#5Rich Shepard
rshepard@appl-ecosys.com
In reply to: Tom Lane (#4)
Re: Blank Numeric Column For INSERT

On Wed, 23 Nov 2011, Tom Lane wrote:

In an insert command, you need to either write NULL or omit the column
from the column list; empty expressions aren't syntactically correct.
(Note that the latter option actually results in inserting the column's
default, not necessarily null...)

Tom,

I must have written Null rather than NULL yesterday evening. That's why
it didn't work for me.

Must be some other glitches but they scroll up too quickly to read. I'll
fix those next.

Many thanks. Happy Thanksgiving.

Rich