Re: [GENERAL] cast issue in WITH RECURION - Mailing list pgsql-general

From k b
Subject Re: [GENERAL] cast issue in WITH RECURION
Date
Msg-id 1502619108.7138419.1501826478820@mail.yahoo.com
Whole thread Raw
In response to [GENERAL] cast issue in WITH RECURION  (k b <k_b0000@yahoo.se>)
List 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


 ----------
Please ignore that last message from me, it does work. Thank you for the answer!
 Karl


pgsql-general by date:

Previous
From: k b
Date:
Subject: Re: [GENERAL] cast issue in WITH RECURION
Next
From: Alexander Farber
Date:
Subject: Re: [GENERAL] Do not INSERT if UPDATE fails