문제

I want to do something like this:

alter table foos
alter column bar type bool using bar::boolean;

bar is currently a text column. Some experimentation shows that postgres will do things like convert a string "t" to boolean true. In my case this is great, but I'd like to read the full behavior before using this. I can't seem to find where this documentation is.

도움이 되었습니까?

해결책

The behavior for boolean

typically you have to go look up every type and to see how it can be cast or look for a function to do the casting

here is a link

Postgresql also supports Create Cast

Information on the pg_cast

다른 팁

This is in the PostgreSQL manual section on the boolean data type:

Boolean constants can be represented in SQL queries by the SQL key words TRUE, FALSE, and NULL.

The datatype input function for type boolean accepts these string representations for the “true” state:

true
yes
on
1

and these representations for the “false” state:

false
no
off
0

Unique prefixes of these strings are also accepted, for example t or n. Leading or trailing whitespace is ignored, and case does not matter.

The datatype output function for type boolean always emits either t or f […]

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 dba.stackexchange
scroll top