Re: actualizar columna fecha

From: "Jaime Casanova" <systemguards(at)gmail(dot)com>
To: José Fermín Francisco Ferreras <josefermin54(at)hotmail(dot)com>
Cc: "foro postgresql" <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: actualizar columna fecha
Date: 2008-01-25 02:27:34
Message-ID: c2d9e70e0801241827i75d192a8ueb212397ef94d88a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

2008/1/24 José Fermín Francisco Ferreras <josefermin54(at)hotmail(dot)com>:
> hola, tengo la siguiente tabla de prueba
>
> create table prueba
> (
> codigo integer primary key,
> fecha date default now()
> );
>
> hago el correspondiente insert a la tabla /* las inserciones fueron en
> fecha 2008-01-23 */
>
> insert into prueba(codigo)
> values
> (1),(2),(3);
>
> entonces modifico el codigo d una d las columnas /* la actualización fue en
> fecha 2008-01-24 */
>
> update prueba
> set codigo = 4
> where codigo = 2;
>
> Bien todo va perfecto, con excepción d q me gustaría q ademas d generar la
> fecha cuando se hace un insert, me gustaría q la generara a la fecha d hacer
> un update osea q modifique la fecha.
>

con un trigger.

CREATE OR REPLACE FUNCTION upd_prueba RETURNS TRIGGER AS $$
begin
NEW.fecha := current_date;
end;
$$ LANGUAGE plpgsql;

CREATE TRIGGER trg_upd_prueba BEFORE UPDATE ON prueba
FOR EACH ROW EXECUTE PROCEDURE upd_prueba();

--
Atentamente,
Jaime Casanova

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs and the universe trying
to produce bigger and better idiots.
So far, the universe is winning."
Richard Cook

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Jaime Casanova 2008-01-25 02:34:10 Re: Problema de Performance
Previous Message frank 2008-01-24 23:21:20 Conectar varios servidores con PgAdmin3