Solved

how to handle postgress missing field data

Posted on 2015-01-05
18
128 Views
Last Modified: 2015-02-16
hello experts,

I have data which 4 field of them have empty fields, but the data is not CSV and their seprator is ";"
I try FORCE NOT NULL, but since that is for CSV only it through error that this option is only available for CSV"

Copy -u username -c "copy tablename '%data' DELIMITER ';' FOCE NOT NILL;"

Open in new window


thanks for help
0
Comment
Question by:hi4ppl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 4
18 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40533011
FOCE NOT NILL  => I hope that this is a typo, it should be: FORCE NOT NULL

for non-CSV, you provide this:
NULL  AS  ''

for example

edit: added the reference:
http://www.postgresql.org/docs/8.1/static/sql-copy.html
0
 
LVL 1

Author Comment

by:hi4ppl
ID: 40533021
Hi,

sorry it was typo... my postgress is 9.3... can you give example based on my code? I could not find any in the web
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40533031
what is nice on the postgre sql document page above is that you can switch directly to the version:
http://www.postgresql.org/docs/9.3/static/sql-copy.html

so, no change there;
NULL '<null string goes here>'
ie;:
Copy -u username -c "copy tablename '%data' DELIMITER ';' NULL '' ;" 

Open in new window

0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 1

Author Comment

by:hi4ppl
ID: 40533060
Thanks,  when I run that it give me error of "

ERROR: missing data for column "location"

Open in new window


the data for this column does not included in RAW files
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40533098
is this a copy "table to file" or "file to table"
0
 
LVL 1

Author Comment

by:hi4ppl
ID: 40533124
hi it's file to table,
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40533203
first, I see that you seem to be using a command line tool "copy", and not the sql version, so there may be differences (I referred to the sql extension syntax)

also, in your syntax I don't see the "FROM" part which specifies the file name

next, does the file have the same number of columns that the table?
if not, I would recommend to use a "staging" table (which matches the file structure), and copy the data from there to the actual table (with a plain INSERT/UPDATE construct) after having loaded (and eventually validated) the data from the file into that staging table
0
 
LVL 1

Author Comment

by:hi4ppl
ID: 40533250
Hi,

sorry to make this confusiton and didn't give clear example, so bellow is how the data is

james;ca;2000
lalith;ca;2000
james;pa;2000

and the table structure is having more columns, that column is for other script that run based on the data and make some calculation.

name|state|salary|bonus

so the data of bonus is not available in the raw files script will calculate this.
regards
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 40533257
I can then only recommend the staging table, as posted above. anything else will give you problems in the long run
0
 
LVL 1

Author Comment

by:hi4ppl
ID: 40533264
Bu stating table will be two times work isn't it ?, is there a way in PostgreSQL where you can do in oracle list the name of fields and assign is  as filler? like in oracle  sqlldr you can do that, what about alternative in PostgreSQL?
0
 
LVL 62

Expert Comment

by:gheist
ID: 40568444
First of all "not null" is not appropriate for your data, as obviously it is null in some cases.
you can add DEFAULT " "
To columns where that is acceptable.
0
 
LVL 1

Author Comment

by:hi4ppl
ID: 40582281
Hi, how do I mention column names in copy command... like we do in oracle control file?
0
 
LVL 62

Expert Comment

by:gheist
ID: 40582299
How is it related to initial question?
Remove "force not null" from your statement and it copies.
0
 
LVL 1

Author Comment

by:hi4ppl
ID: 40582309
Hi,

this is how my raw data is :

james;ca;2000
lalith;ca;2000
james;pa;2000

and this is how my table structure is
name|state|salary|bonus

the reason why bonus is their that this will be done via PL/pgSQL... so during the loading i'm getting that number column in file is less than the raw data and it expect more data after the last row.
0
 
LVL 62

Expert Comment

by:gheist
ID: 40582312
Yes, follow the advice given here multiple times.
0
 
LVL 1

Author Comment

by:hi4ppl
ID: 40582317
I only get advise to load the data two times, once load all and then create another table out of that table as staging area.... I only asked if there is any option like oracle have for setting the field as FILLER while loading... that advise is not solution for my problem that I was asking....
0
 
LVL 62

Expert Comment

by:gheist
ID: 40582321
You hit NULL fields with FORCE NOT NULL.
I suppose that is already addressed.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question