Como sair da lista?
Em 18/01/2016 12:24, "Euler Taveira" <[email protected]> escreveu:

> On 15-01-2016 18:58, Pablo Farias wrote:
> > Para inclusao de registro  ficou perfeito mais e para quando ouver
> > alteração, no registro preciso atualizar o campo data_atualizacao.
> >
> > Com a opção default nao deu certo
> >
> Não há necessidade de gatilho para INSERT ou UPDATE se você utilizar o
> termo DEFAULT no lugar do valor. Veja:
>
> foo=# create table teste (a integer, b text default 'teste', c timestamp
> with time zone default current_timestamp);
> CREATE TABLE
> foo=# insert into teste (a) VALUES(123);
> INSERT 0 1
> foo=# select a, b, c from teste;
>   a  |   b   |               c
> -----+-------+-------------------------------
>  123 | teste | 2016-01-18 11:16:49.591478-03
> (1 registro)
>
> foo=# insert into teste (a, b) VALUES(456, 'foo');
> INSERT 0 1
> foo=# select a, b, c from teste;
>   a  |   b   |               c
> -----+-------+-------------------------------
>  123 | teste | 2016-01-18 11:16:49.591478-03
>  456 | foo   | 2016-01-18 11:17:36.760013-03
> (2 registros)
>
> foo=# update teste set b = DEFAULT where a = 456;
> UPDATE 1
> foo=# select a, b, c from teste;
>   a  |   b   |               c
> -----+-------+-------------------------------
>  123 | teste | 2016-01-18 11:16:49.591478-03
>  456 | teste | 2016-01-18 11:17:36.760013-03
> (2 registros)
>
> foo=# insert into teste (a, b, c) values(789, 'bar', DEFAULT);
> INSERT 0 1
> foo=# select a, b, c from teste;
>   a  |   b   |               c
> -----+-------+-------------------------------
>  123 | teste | 2016-01-18 11:16:49.591478-03
>  456 | teste | 2016-01-18 11:17:36.760013-03
>  789 | bar   | 2016-01-18 11:21:09.560375-03
> (3 registros)
>
>
> --
>    Euler Taveira                   Timbira - http://www.timbira.com.br/
>    PostgreSQL: Consultoria, Desenvolvimento, Suporte 24x7 e Treinamento
> _______________________________________________
> pgbr-geral mailing list
> [email protected]
> https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a