Firebird doesn't accept VARCHAR without length specified / disambiguate CAST/CREATE TABLE in types?

Issue #2505 resolved
Former user created an issue

When specifying a types.Unicode() without a length, sqlalchemy generated create table SQL translates this as ''VARCHAR'' without length specified, which Firebird doesn't accept.

IMHO, in this case sqlalchemy has been raised exc.CompileError. The attached patch implements this behavior.

Comments (6)

  1. Mike Bayer repo owner

    does firebird allow this SQL:

    SELECT CAST(somecolumn AS VARCHAR) FROM table
    

    or is length required in this case as well ?

    If not, then we can't at the moment raise CompileError in this location, as visit_VARCHAR is the compile vector for both CREATE TABLE and CAST.

    We can enhance the type compiler system to allow **kwargs so that a flag like "is_create=True" can be sent to disambiguate. This would at the moment be something I'd consider for 0.8.

  2. Former user Account Deleted

    Unfortunately, this information is missing in documentation (or I'm not looking for in the right place), but if we try to execute this code in isql-fb, then we get an error if do not specify a length of VARCHAR:

    $ isql-fb -user sysdba -password masterkey
    SQL> CONNECT DATABASE 'example.fbd';
    SQL> CREATE TABLE SETTINGS (id int not null, key varchar(32), val varchar(127), constraint example_id_pk primary key (id));
    SQL> INSERT INTO SETTINGS values('key1', 'val1');
    SQL> SELECT CAST(id as VARCHAR) FROM SETTINGS;
    Statement failed, SQLSTATE = 42000
    Dynamic SQL Error
    -SQL error code = -104
    -Token unknown - line 1, column 26
    -)
    SQL> SELECT CAST(id as VARCHAR(12)) FROM SETTINGS;
    
    CAST         
    ============ 
    1
    
    SQL> SELECT CAST(key as VARCHAR) FROM SETTINGS;
    Statement failed, SQLSTATE = 42000
    Dynamic SQL Error
    -SQL error code = -104
    -Token unknown - line 1, column 27
    -)
    SQL> SELECT CAST(key as VARCHAR(32)) FROM SETTINGS;
    
    CAST                             
    ================================ 
    key1
    
  3. Log in to comment