Thread: explicit cast for null::bigint

explicit cast for null::bigint

From
Ivan Sergio Borgonovo
Date:
I've found this a bit strange:

insert into catalog_related (itemid, related_itemid, rank)
        select distinct itemid, null::bigint, 0::float4
                from catalog_categoryitem
                where catid is null or catid<>0
                and itemid not in (select itemid from
                catalog_related);

create table catalog_related (
  itemid bigint,
  updated timestamp default now(),
  related_itemid bigint,
  rank float4
);

without the explicit cast for the null I get

ERROR:  column "related_itemid" is of type bigint but expression is
of type text LINE 1: insert into catalog_related (itemid,
related_itemid, rank) ^

HINT:  You will need to rewrite or cast the expression.
PostgreSQL 8.3.4 on x86_64-pc-linux-gnu

--
Ivan Sergio Borgonovo
http://www.webthatworks.it