Why can't I double quote built-in type names in Postgres? Why can't I double quote the primary built-in type names in Postgres despite being able to double quote their aliases?  For example, these work fine

SELECT CAST (1 as bool);
SELECT CAST (1 as "bool");
SELECT CAST (1 as boolean);
SELECT CAST (1 as int8);
SELECT CAST (1 as "int8");
SELECT CAST (1 as bigint);


but these fail

SELECT CAST (1 as "boolean");
SELECT CAST (1 as "bigint");


(See http://www.sqlfiddle.com/#!17/a6ad3/13)
You can only quote identifiers, but not keywords. Data types prescribed by the SQL standard, such as int, integer, boolean, bigint etc. are keywords and, when put in quotes, are not recognised as such, producing errors. bool and int8, on the contrary, are, as you say, Postgres-specific aliases and are therefore identifiers, which allows them to be quoted.

Note that aliases follow the rules for quoted identifiers:

SELECT CAST (1 as BOOL); -- succeeds
SELECT CAST (1 as "BOOL"); -- fails




A little explanation of how the parser works. 


  A token can be a key word, an identifier, a quoted identifier, a literal (or constant)


The order of precedence in the quote above is significant. When seeing an unquoted sequence of characters, the parser converts it to lowercase and first tries to match it against the known keywords. If unsuccessful, it will then try to find an identifier with that name. When seeing a quoted character sequence the parser knows that this must be an identifiers (since keywords are never quoted).

So,


BOOLEAN --> to lowercase --> boolean --> is keyword? yes --> done.
BOOL --> to lowercase --> bool --> is keyword? no --> is identifier? yes --> alias for boolean --> done.
"BOOL" --> quoted identifier, don't change case --> does not exist --> done.