Re: Need some help converting MS SQL stored proc to postgres function

Поиск
Список
Период
Сортировка
От Tino Wildenhain
Тема Re: Need some help converting MS SQL stored proc to postgres function
Дата
Msg-id 49858D35.4090906@wildenhain.de
обсуждение исходный текст
Ответ на Need some help converting MS SQL stored proc to postgres function  (Mike Christensen <imaudi@comcast.net>)
Ответы Re: Need some help converting MS SQL stored proc to postgres function  (Mike Christensen <imaudi@comcast.net>)
Список pgsql-general
Hi,

Mike Christensen wrote:
> Hi guys, I'm in the process of migrating my database from MS SQL 2005 to
> PostgreSQL and there's one final stored proc that's giving me some
> problems..  Perhaps someone can give me some help?  Here's the sproc:
>
>  SELECT
>    RecipeId, Avg(Rating) as Rating
>  INTO #ratings
>  FROM RecipeRatings GROUP BY RecipeId
>
>  UPDATE Recipes
>    SET Rating = #ratings.Rating FROM Recipes INNER JOIN #ratings ON
> (#ratings.RecipeId = Recipes.RecipeId AND #ratings.Rating <>
> Recipes.Rating)

would not

UPDATE receipes
    SET rating = r.rating
   FROM (SELECT recipeid,avg(rating) as rating
         GROUP BY recipeid) r
   WHERE recipeid=r.recipeid
     AND rating <> r.rating

work too w/o temp table?
(untested, can contain errors)

Tino

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: "Paolo Saudin"
Дата:
Сообщение: R: complex custom aggregate function
Следующее
От: Dean Rasheed
Дата:
Сообщение: Re: Pet Peeves