cannot change data type of view column SQL
<p>I keep getting this error</p>

<blockquote>
  <p>cannot change data type of view column "percent" from integer to double precision</p>
</blockquote>

<p>I have a function called <code>findIntl()</code> which returns a float</p>

<pre><code>create or replace function findIntl(integer) returns float as $$
  select cast(count(*) as float)
  from students s
  join program_enrolments pe on (s.id = pe.student)
  where s.stype = 'intl' and pe.semester = $1;
$$ language sql;
</code></pre>

<p>and I use the returned value in a view called findPercent</p>

<pre><code>create or replace view findPercent(semester, percent) as
  select q6(s.id), findIntl(s.id)
  from semesters s
  where s.id = id and s.term ~ 'S' and s.year &gt;= 2004;
</code></pre>

<p>If I replace <code>findIntl()</code> with another column of values it works perfectly fine but when <code>findIntl()</code> is there it says <code>cannot change data type of view column "percent" from integer to double precision</code></p>

<p>If I <code>cast(findIntl(s.id) as numeric(4,2)</code> it says</p>

<blockquote>
  <p>ERROR:  cannot change data type of view column "percent" from integer to numeric(4,2)</p>
</blockquote>

<p>I have read on stackoverflow about something to do with dropping tables but I don't quite understand why I must do that, and I am not even sure if it applies to this case. </p>

<p>Also, if I remove semester from findPercent and just keep percent there and <code>select findIntl(s.id)</code> only then it says</p>

<blockquote>
  <p>ERROR:  cannot drop columns from view</p>
</blockquote>

<p>I'm new to SQL so sorry for my ignorance but when I use a column of integers it works perfectly fine but when I use a function to return values why does this break and how can I fix this?</p>