Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error parsing Oracle SQL with CURRENT_TIMESTAMP #141

Closed
hazardv opened this issue Aug 10, 2022 · 3 comments
Closed

Error parsing Oracle SQL with CURRENT_TIMESTAMP #141

hazardv opened this issue Aug 10, 2022 · 3 comments

Comments

@hazardv
Copy link
Contributor

hazardv commented Aug 10, 2022

When attempting to parse Oracle SQL where a column definition has a default value of CURRENT_TIMESTAMP the parser will fail with the following error:

ERROR (line 1): Invalid statement: Was expecting remark, or run, or
                       prompt, or create, or table comment, or comment on
                       table, or comment on column, or alter, or drop
translate: Error with parser 'SQL::Translator::Parser::Oracle': Parse failed.

You can recreate the error with the following script:

#!/usr/bin/env perl
 
use strict;
use warnings;
use FindBin;
use SQL::Translator;

my $translator          = SQL::Translator->new(
    # Print debug info
    debug               => 1,
    # Print Parse::RecDescent trace
    trace               => 1,
    # Don't include comments in output
    no_comments         => 0,
    # Print name mutations, conflicts
    show_warnings       => 1,
    # Add "drop table" statements
    add_drop_table      => 1,
    # to quote or not to quote, thats the question
    quote_identifiers     => 1,
    # Validate schema object
    validate            => 1,
    # Make all table names CAPS in producers which support this option
    format_table_name   => sub {my $tablename = shift; return uc($tablename)},
    # Null-op formatting, only here for documentation's sake
    format_package_name => sub {return shift},
    format_fk_name      => sub {return shift},
    format_pk_name      => sub {return shift},
);
 
my $output     = $translator->translate(
    from       => 'Oracle',
    to         => 'MySQL',
    # Or an arrayref of filenames, i.e. [ $file1, $file2, $file3 ]
    filename   => "$FindBin::Bin/../db_versions/just_person_test.sql",
) or die $translator->error;
 
print $output;

just_person_test.sql contains the following

    CREATE TABLE person (
        id varchar2(32) NOT NULL, 
        added date DEFAULT CURRENT_TIMESTAMP, 
        PRIMARY KEY (id)
    );

If you remove DEFAULT CURRENT_TIMESTAMP it will parse just fine.

@hazardv
Copy link
Contributor Author

hazardv commented Aug 24, 2022

Bump

@hazardv
Copy link
Contributor Author

hazardv commented Sep 6, 2022

I anyone actively working on this project?

@hazardv
Copy link
Contributor Author

hazardv commented Feb 23, 2024

Resolved with pull request #142

@hazardv hazardv closed this as completed Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant