Re: cast issue in WITH RECURION

From: k b <k_b0000(at)yahoo(dot)se>
To: <pgsql-general(at)postgresql(dot)org>
Cc: Alban Hertroys <haramrae(at)gmail(dot)com>
Subject: Re: cast issue in WITH RECURION
Date: 2017-08-04 05:54:19
Message-ID: 1968805008.1109121.1501826059769@mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> when i
create a recursive query and try to add the distances i get
a message:
> ERROR:  recursive query
"edges" column 3 has type numeric(7,3) in
non-recursive term but type numeric overall.

> My exercise is almost
identical to the example in the docs:
>
WITH RECURSIVE search_graph(id, link, data, depth, path,
cycle) AS (
>        SELECT g.id,
g.link, g.data, 1,
>         
ARRAY[g.id],
>          false
>        FROM graph g
>      UNION ALL

      SELECT g.id, g.link,
>     
  sg.data + g.data, -- altered section, data is
numeric(7,3)
>        sg.depth +
1,
>          path || g.id,
>          g.id = ANY(path)
>        FROM graph g, search_graph
sg
>        WHERE g.id = sg.link AND
NOT cycle
> )
> SELECT
* FROM search_graph;

I believe the solution is rather simple; just
cast(sg.data + g.data to numeric(7,3))

Alban Hertroys

----------
Tried that and it did not work.
cast(sg.data + g.data AS numeric(7,3)) but the same error is produced, even if i cast the g.data in the non-recursive section. Same issue if i cast each column individually.

Karl

Browse pgsql-general by date

  From Date Subject
Next Message k b 2017-08-04 06:01:18 Re: cast issue in WITH RECURION
Previous Message Lucas Possamai 2017-08-04 04:03:59 Re: hot standby questions