rubysequelpgsequel-gem

Disable double underscore behaviour for Sequel


How disable double underscore behaviour for Sequel?

I work with legacy data base schema where I have a lot of columns with "__" in name.

db[:abc].insert({vector_a__c: "356"})
Sequel::DatabaseError: PG::UndefinedColumn: ERROR:  column "vector_a" of relation "abc" does not exist
LINE 1: INSERT INTO "abc" ("vector_a"."c") VALUES ('356') RETURNING ...

Solution

  • In general you want to wrap it in an identifier:

    db[:abc].insert(Sequel.identifier(:vector_a__c) => "356")
    

    Using a string as an identifier only works in very few cases for backwards compatibility, where it is unambiguous (i.e. where an SQL string would not be valid).