PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > mysql.general > Problem with mysqlimport and timestamp
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Problem with mysqlimport and timestamp

Réponse
 
LinkBack Outils de la discussion
Vieux 18/10/2007, 16h37   #1
qt4x11
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Problem with mysqlimport and timestamp

Hi-
I'm using the command 'mysqlimport -u usr -ppassh -h mysqlserver -P 3306 -v
db --local $workdir/$filename'to import a table into mysql from a file
$filename.

The data in $filename looks something like:

test test

where there is a blank space between the two 'test's to represent an empty
column. This column is of type datetime NULL DEFAULT NULL in the database.
The blank space between the two 'test's gets imported as (err) instead of
NULL.


Is there a way I can import empty column data as NULL? I'd like there to be
a NULL for every row for which this column is empty. I'm not sure how to do
this given the format of my $filename. As a check, I tried inserting a row
at the top of $filename like

test

The row was imported correctly, as in there was a NULL in the timestamp
column in the database, as well as a NULL in the next column in the
database. So, this may have something to do with the format of the
$filename, but I may not be able to control the format of that file.

Thanks.

  Réponse avec citation
Vieux 18/10/2007, 17h54   #2
mysql@subtropolix.org
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problem with mysqlimport and timestamp

qt4x11 wrote:
> Hi-
> I'm using the command 'mysqlimport -u usr -ppassh -h mysqlserver -P 3306 -v
> db --local $workdir/$filename'to import a table into mysql from a file
> $filename.
>
> The data in $filename looks something like:
>
> test test
>
> where there is a blank space between the two 'test's to represent an empty
> column. This column is of type datetime NULL DEFAULT NULL in the database.
> The blank space between the two 'test's gets imported as (err) instead of
> NULL.
>
>
> Is there a way I can import empty column data as NULL? I'd like there to be
> a NULL for every row for which this column is empty. I'm not sure how to do
> this given the format of my $filename. As a check, I tried inserting a row
> at the top of $filename like
>
> test
>
> The row was imported correctly, as in there was a NULL in the timestamp
> column in the database, as well as a NULL in the next column in the
> database. So, this may have something to do with the format of the
> $filename, but I may not be able to control the format of that file.
>
> Thanks.
>


You should alter your data like so:

test \N test

That is, separate the fields with a tab and place "\N" wherever you want
a NULL. As it is, the data is being misinterpreted, which is why the
second import you mentioned worked--there was nothing after the first
field to be erroneously put into the timestamp field.

If the data comes from somewhere else you will need to parse it out and
re-write it using proper formatting, i'm afraid.

brian
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 10h23.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08999 seconds with 10 queries