PostgreSQL extending a variable-width bit string type?
Using overlay

From the docs


  The following SQL-standard functions work on bit strings as well as character strings: length, bit_length, octet_length, position, substring, overlay.


PostgreSQL supports overlay on Bit Strings in two forms


overlay(bit,bit,int)
overlay(bit,bit,int,int)


You can use it like this,

CREATE FUNCTION type_test(_x bit)
RETURNS bit AS $$
  SELECT overlay(B'00' PLACING _x FROM 2 FOR 0);
$$ LANGUAGE sql;
SELECT type_test(X'ff');

 type_test  
------------
 0111111110


Using "bit"

You can can also use the internal and undocumented "bit"

CREATE FUNCTION type_test(_x bit)
RETURNS bit AS $$
  SELECT ('0' || _x::text || '0')::"bit";
$$ LANGUAGE sql;

SELECT type_test(X'55');
 type_test  
------------
 0111111110