dimitri / pgloader

Migrate to PostgreSQL in a single command!
http://pgloader.io
Other
5.45k stars 548 forks source link

MSSQL transfer cannot CAST tables that start with a digit #474

Closed xbogdan closed 7 years ago

xbogdan commented 8 years ago

Trying to transfer from MSSQL to PostgreSQL I can't make this work. I'm trying to drop the default value for a column because the default value is N'Title and it seems to mess up with the parser.

$ pgloader -V
pgloader version "3.2.2"
compiled with SBCL 1.3.11
LOAD DATABASE
    FROM mssql://<user>:<password>@<hostname>/<dbname>
    INTO postgresql://postgres:@127.0.0.1/test

    WITH schema only, downcase identifiers, quote identifiers
    CAST column Page.title when default "N'Title" to Page.title drop default
;

Error:

An unhandled error condition has been signalled: At

  LOAD DATABASE

  ^ (Line 1, Column 0, Position 0)

Could not parse subexpression ";" when parsing

 Expression PGLOADER.PARSER::COMMANDS
    Subexpression (+ PGLOADER.PARSER::COMMAND)
    Subexpression PGLOADER.PARSER::COMMAND
    Subexpression (AND
                   (OR PGLOADER.PARSER::LOAD-ARCHIVE
                       PGLOADER.PARSER::LOAD-CSV-FILE
                       PGLOADER.PARSER::LOAD-FIXED-COLS-FILE
                       PGLOADER.PARSER::LOAD-COPY-FILE
                       PGLOADER.PARSER::LOAD-DBF-FILE
                       PGLOADER.PARSER::LOAD-IXF-FILE
                       PGLOADER.PARSER::LOAD-MYSQL-DATABASE
                       PGLOADER.PARSER::LOAD-MSSQL-DATABASE
                       PGLOADER.PARSER::LOAD-SQLITE-DATABASE)
                   PGLOADER.PARSER::END-OF-COMMAND)
    Subexpression PGLOADER.PARSER::END-OF-COMMAND
    Subexpression (AND PGLOADER.PARSER::IGNORE-WHITESPACE #\;
                       PGLOADER.PARSER::IGNORE-WHITESPACE)
    Subexpression ";"

;
; compilation unit aborted
;   caught 1 fatal ERROR condition

Here is the PostgreSQL create table statement that it generates without the CAST. You can definitely see that the problem is the default value for column title.

ERROR:  syntax error at or near "Title" at character 191
CREATE TABLE "Page"
    (
      projectid              bigserial not null,
      projectname            text not null,
      title                           text default 'N'Title'',
      scheduletype           int default '0',
    );
xbogdan commented 8 years ago

I think I found the problem. My table name starts with a number/digit and the parse only accepts alpha-char-p which, I think, is a letter.

dimitri commented 7 years ago

I think this got fixed in 3fac222.