Обсуждение: Script for reading flat file without delimiters
Hy everybody,
I have to write a function that takes a flat file name in parameter and load a table with the file information.
I think that it has to read the file line per line and parse each one to retreive each column data.
There is NO DELIMITERS between fields.
Can someone help.
Thanks in advance.
Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les tarifs exceptionnels pour appeler la France et l'international. Téléchargez la version beta.
Mehdi Aboulkassim schrieb: > Hy everybody, > > I have to write a function that takes a flat file name in parameter and > load a table with the file information. Which programming languages do you plan to use? > I think that it has to read the file line per line and parse each one to > retreive each column data. probably. > There is NO DELIMITERS between fields. > How can the fields identified then? Fixed size? You need to provide much more details - otoh, it should not be too hard with a scripting language and just some script you write. Regards Tino
On Thu, Jun 29, 2006 at 03:10:03PM +0200, Mehdi Aboulkassim wrote: > I have to write a function that takes a flat file name in parameter > and load a table with the file information. Does it matter if this function runs on the server side or in the client? > I think that it has to read the file line per line and parse each > one to retreive each column data. > > There is NO DELIMITERS between fields. How are field boundaries recognized? By column position? By patterns in the content? This might be easiest with a language like Perl, Python, Tcl, etc., whether on the client side or in a server-side function written in one of those languages (PL/Perl, PL/Python, PL/Tcl, etc.). You could do it with SQL but other languages are more suitable for text parsing. -- Michael Fuhr
Mehdi Aboulkassim schrieb: > If I had to write it in java, I wouldn't mail this issue. > > I somewhat a Neophyte in Postrgres that's why I need your help. > > I've searched in the netbut I haven't found a script in Plpgsql that can > read a file. > Can you tell me if we can do this in Plpgsql? No you cant read in a file like that with psql. You cant access filesystem with plpgsql either (quick check in the docs would have tell you that...) I was suggesting you write at least a converter program in whatever language you are confortable with. May it be java or whatever. In that script you either access the database directly (usual JDBC stuff) either via ordinary INSERT INTO ... statements or if you feel desparete with COPY FROM STDIN and then streaming. IF thats too hard for you, just write a converter which reads your file and outputs a regular CSV file. You can then use psql command line tool to pull this into the database (via its COPY function) or via backend with the COPY SQL command. If thats all too complex for you, I'm sorry you should stay away from coding... Regards Tino Wildenhain