Thread: PostgreSQL Trigger and rows updated

PostgreSQL Trigger and rows updated

From
Albert
Date:
am trying to update a table according to this trigger :

    CREATE TRIGGER alert
    AFTER UPDATE ON cars
    FOR EACH ROW
    EXECUTE PROCEDURE update_cars();

Trigger Function :

    CREATE FUNCTION update_cars()
    RETURNS 'TRIGGER'
    AS $BODY$
    BEGIN
    IF (TG_OP = 'UPDATE') THEN
    UPDATE hello_cars SET status = new.status
    WHERE OLD.ID = NEW.ID;
    END IF;
    RETURN NULL;
    END;
    $$ LANGUAGE plpgsql;

the trigger works fine. when cars table updated, the hello_cars table
updated but status column in each row is updated and contains same new
status ! it must be updated according to car ID.
i think my problem is in condition : WHERE OLD.ID = NEW.ID;
but can't tell what's wrong exactly

Thanks in advanced

--
View this message in context:
http://postgresql.1045698.n5.nabble.com/PostgreSQL-Trigger-and-rows-updated-tp5608591p5608591.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

Re: PostgreSQL Trigger and rows updated

From
"Daniel Verite"
Date:
    Aleksander Rozman wrote:

> Now I am not sure two of this directories are old databases, but I think
> they are... Is there a way to register one of this databases into new
> installation (I am sure that directory "1" is old postgres database, and
> "11563" is my database I want to save, and "11564" is new postgresql
> database (this is only directory with new date).

Actually 1, 11563 and 11564 are what you get with a fresh new installation.
On a 8.4 install on Ubuntu, the corresponding databases are:

SELECT oid, datname from pg_database where oid in (1,11563,11564);

  oid  |  datname
-------+-----------
     1 | template1
 11563 | template0
 11564 | postgres

Also normally initdb wouldn't work on a non-empty data directory, anyway.
I'd say that either the old data directory has been moved aside at some point
of the upgrade procedure, or it has been wiped out :(

Best regards,
--
Daniel
PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org

Re: PostgreSQL Trigger and rows updated

From
Albert
Date:
Thanks you so much!
it works great now

--
View this message in context:
http://postgresql.1045698.n5.nabble.com/PostgreSQL-Trigger-and-rows-updated-tp5608591p5609895.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

Re: problem after upgrade db missing

From
Aleksander Rozman
Date:
On 6/6/2012 2:35 AM, Daniel Verite wrote:
>     Aleksander Rozman wrote:
>
>> Now I am not sure two of this directories are old databases, but I think
>> they are... Is there a way to register one of this databases into new
>> installation (I am sure that directory "1" is old postgres database, and
>> "11563" is my database I want to save, and "11564" is new postgresql
>> database (this is only directory with new date).
> Actually 1, 11563 and 11564 are what you get with a fresh new installation.
> On a 8.4 install on Ubuntu, the corresponding databases are:
>
> SELECT oid, datname from pg_database where oid in (1,11563,11564);
>
>    oid  |  datname
> -------+-----------
>       1 | template1
>   11563 | template0
>   11564 | postgres
>
> Also normally initdb wouldn't work on a non-empty data directory, anyway.
> I'd say that either the old data directory has been moved aside at some point
> of the upgrade procedure, or it has been wiped out :(
>
> Best regards,
Problem is that upgrade of Ubuntu failed at some point, and after that I
did clean install... So database probably got deleted at some point.

Andy