hi4ppl
asked on
how to handle postgress missing field data
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"
thanks for help
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;"
thanks for help
ASKER
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
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
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;:
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 '' ;"
ASKER
Thanks, when I run that it give me error of "
the data for this column does not included in RAW files
ERROR: missing data for column "location"
the data for this column does not included in RAW files
is this a copy "table to file" or "file to table"
ASKER
hi it's file to table,
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
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
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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.
you can add DEFAULT " "
To columns where that is acceptable.
ASKER
Hi, how do I mention column names in copy command... like we do in oracle control file?
How is it related to initial question?
Remove "force not null" from your statement and it copies.
Remove "force not null" from your statement and it copies.
ASKER
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.
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.
Yes, follow the advice given here multiple times.
ASKER
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....
You hit NULL fields with FORCE NOT NULL.
I suppose that is already addressed.
I suppose that is already addressed.
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