Consider the following:
CREATE TEMP TABLE tbl ( id SERIAL NOT NULL, PRIMARY KEY (id) );
COPY tbl (id) FROM stdin; 1 2 3 4 \.
SELECT substring ('1234567890' FOR (SELECT count (*) FROM tbl)::int);
This returns '1234', as expected. But
SELECT substring ('1234567890' FOR (SELECT count (*) FROM tbl));
returns NULL. I think the problem is that "SELECT count(*)" returns a
BIGINT whereas "substring" expects an INT. Shouldn't there be a warning?