Is there any technique to do in postgresql 9.3 so that it start returning 1 and 0 instead of “t” and “f” for boolean type

前端 未结 2 1599
[愿得一人]
[愿得一人] 2021-01-23 05:40

Actually i am migrating my ms sql server into postgresql 9.3 and we were using int data type to store 1 and 0 for boolean values but in postgresql9.3 it is not possible. what di

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-23 05:47

    if the column if of the boolean type then cast it to integer to compare to integer:

    select the_boolean_column::int = 1;
    

    to insert a boolean value as smallint cast it to integer fisrt

    insert into t (integer_column) values (boolean_value::int::smallint)
    

    to make the boolean_column always return integer create a view

    create view v as
    select boolean_column::int as integer_column
    from t
    

    When you query a boolean column it does not return 't' or 'f'. It returns a boolean value, true or false or null. The string representation of the value is up to the client, hence the 't'.

提交回复
热议问题