activerecord - sqlite3 boolean field stored as 't', 'f', not compatible with postgresql -



activerecord - sqlite3 boolean field stored as 't', 'f', not compatible with postgresql -

i have user table in sqlite3 schema:

create table "users" ( "id" integer primary key autoincrement not null, "email" varchar(255) default '' not null, "encrypted_password" varchar(255) default '' not null, "admin" boolean,);

which has boolean field admin.

i add together user record rails console:

user.create!({email: "example@example.com", encrypted_password: "sample string", admin:1})

then when query user record admin field

select * users admin=1;

it returns empty result set.

i had @ sqlite users table, admin field saved string 't' , 'f'.

this cause problem, when utilize custom query in rails, admin filter not compatible sqlite3, test database, , postgresql, dev , production database.

how overcome problem?

if must utilize raw sql, should utilize same dbms in development, testing, , production. postgresql run fine on windows, linux, , osx.

this of import when comes sqlite, doesn't back upwards info types @ in way sql databases do. sqlite allows kind of literal nonsense.

sqlite> create table test (n integer not null); sqlite> insert test values ('wibble'); sqlite> select n test; wibble

but query that's giving problem won't run in postgresql anyway. query

select * users admin=1;

will raise error in postgresql, because integer 1 isn't value in domain of boolean values. the string '1' is valid value, though. work.

select * users admin='1';

as this.

select * users admin='t';

postgresql activerecord ruby-on-rails-4 sqlite3

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -