Re: new and old not available in rule subselects?

Поиск
Список
Период
Сортировка
От Shane Ambler
Тема Re: new and old not available in rule subselects?
Дата
Msg-id 454B2253.5060803@007Marketing.com
обсуждение исходный текст
Ответ на new and old not available in rule subselects?  (Egil Möller <redhog@redhog.org>)
Ответы Re: new and old not available in rule subselects?  ("redhog" <redhog@redhog.org>)
Список pgsql-general
Egil Möller wrote:
> It seems like you can not use the magical relations new and old in
> sub-selects in rules. Why is this, or is there something I haven't
> understood correctly about rules and new and old?
>
> create table "user" (
>  username varchar,
>  created timestamp  default now(),
>  detstroyed timestamp default null);
>
> create table users (
>  time timestamp,
>  users bigint);
>
> create rule user_insert_count as
>  on update to "user"
>  do also
>   select
>    new.created, (select count(*) from new where destroyed is null)
>   into users
>   from new;
>
> ERROR:  relation "*NEW*" does not exist
>
> Thanks in advance,
> Egil

select count(*) from new ??? - new refers to a record not a table name

Try

create rule user_insert_count as
  on update to "user"
  do also
   insert into users (time,users) values (
    new.created, (select count(*) from "user" where destroyed is null));


--

Shane Ambler
pgSQL@007Marketing.com

Get Sheeky @ http://Sheeky.Biz

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

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: start up and shut down script
Следующее
От: "Magnus Hagander"
Дата:
Сообщение: Re: Counting records in a PL/pgsql cursor