[erlang-questions] importing sql data

Robert Raschke <>
Wed Mar 4 17:12:50 CET 2009


On Wed, Mar 4, 2009 at 2:54 PM, Joe Armstrong <> wrote:
> I have a file, which if run into sql builds a data base.
>
> It starts like this:
>
> # For updates to this file, see http://27.org/isocountrylist/
> # Created by getisocountrylist.pl on Sun Nov  2 14:59:20 2003.
> # Wm. Rhodes <>
>
> CREATE TABLE IF NOT EXISTS country (
>  iso CHAR(2) NOT NULL PRIMARY KEY,
>  name VARCHAR(80) NOT NULL,
>  printable_name VARCHAR(80) NOT NULL,
>  iso3 CHAR(3),
>  numcode SMALLINT
> );
>
> INSERT INTO country VALUES ('AF','AFGHANISTAN','Afghanistan','AFG','004');
> INSERT INTO country VALUES ('AL','ALBANIA','Albania','ALB','008');
> INSERT INTO country VALUES ('DZ','ALGERIA','Algeria','DZA','012');
>
> Has anybody the *obvious* bit of code I want.
>
> It parses the table definition, then reads all the table entries, type
> checking them
> against the table definition and returns everything in a single term.
> Alternatively a
> "fold" version that folds a function over the parsed and type checked entries.
>
> Surely somebody must have written this ...
>
> /Joe Armstrong

Parsing SQL takes real dedication. Especially if you want to be able
to go beyond just MySQL.

Are there any free libraries out there that are able to translate SQL
text (especially the DDL bit, where vendors go out of their way to be
non-standard) into a suitable abstract form for further processing?

Hmm, actually, now thinking of it, the MySQL dump format is along the
lines of Joe's example. Maybe it's possible to access the parsing of
that somehow and use it in a port program? I'm not familiar with the
code of MySQL, so this might be futile, but you never know.

Robby



More information about the erlang-questions mailing list