![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I am looking for the rough equivalent of: mysqlimport -L -h <host> -r --fields-terminated-by=',' -u<user> -p<pass --fields-enclosed-by='"' genekeydb *csv >report In particular, I have '"' enclosed fields. |
#3
| |||
| |||
|
|
At 9:13 AM -0400 9/17/04, Sean Davis wrote: I am looking for the rough equivalent of: mysqlimport -L -h <host> -r --fields-terminated-by=',' -u<user -p<pass --fields-enclosed-by='"' genekeydb *csv >report In particular, I have '"' enclosed fields. As far as I know there's nothing to determine enclosed fields with postgresql and you'll have to trim these '"' off after the import. For the import, what you're looking for is COPY TO/FROM ... Here's the documentation on COPY: http://www.postgresql.org/docs/7.4/i.../sql-copy.html If this is a one time operation that you don't need to program into your solution you can easily do it with Eduphant from any Win or Mac client: <http://aliacta.com/download In Eduphant, click the "stdin" button to select the file you want to import, then type the appropriate COPY command and execute it. General caveat on imports: make sure you don't mix up text encodings! Cheers, Marc |
#4
| |||
| |||
|
|
Marc, Thanks. That is what I had thought. Another detail--I have fields (including some dates) that include "" (empty fields). What is the best way to deal with those? Should I just convert them to NULL (assuming that was the actual meaning) and then use that as the NULL string in the copy command? |
#5
| |||
| |||
|
|
At 9:37 AM -0400 9/17/04, Sean Davis wrote: Marc, Thanks. That is what I had thought. Another detail--I have fields (including some dates) that include "" (empty fields). What is the best way to deal with those? Should I just convert them to NULL (assuming that was the actual meaning) and then use that as the NULL string in the copy command? Sean, I think you could try that. You may leave them empty as well (after stripping '"') and use that for NULL with the COPY command. Marc |
#6
| |||
| |||
|
|
Marc, That seemed to get most of the way (setting to NULL). However, it seems that does not work for integer columns? I'm still getting an error: ERROR: invalid input syntax for integer: "NULL" CONTEXT: COPY cgap_lib,line 1, column clones: "NULL" |
#7
| |||
| |||
|
|
At 12:31 PM -0400 9/17/04, Sean Davis wrote: Marc, That seemed to get most of the way (setting to NULL). However, it seems that does not work for integer columns? I'm still getting an error: ERROR: invalid input syntax for integer: "NULL" CONTEXT: COPY cgap_lib,line 1, column clones: "NULL" Your text columns will probably have imported the text "NULL." From http://www.postgresql.org/docs/7.4/i.../sql-copy.html "null string The string that represents a null value. The default is \N (backslash-N). You might prefer an empty string, for example." You can choose your own null string with: [ NULL [ AS ] 'null string' ] ] Marc |
![]() |
| Thread Tools | |
| Display Modes | |
| |