Em 2 de dezembro de 2010 09:03, Marcelo Silva <[email protected]> escreveu: > Pessoal tenho o seguinte campo > > f01_cadastro date NOT NULL DEFAULT '2010-12-02'::date, > > Eu coloquei como default > 'NOW' e ele mudou pra data de hoje. > Minha intenção é que o valor Dafault seja a data em que o registro estiver > sendo inserido. > Já aproveitando o gancho, também queria saber como colocar o valor Hora por > Default também. > > Ex. > > Create Table teste) > campo_data date default 'now', > campo_hora time... default 'now' > ) > > Existe isso ou terei que criar um trigger? >
Do manual: SELECT CURRENT_TIMESTAMP; SELECT now(); SELECT TIMESTAMP 'now'; -- incorrect for use with DEFAULT Tip: You do not want to use the third form when specifying a DEFAULT clause while creating a table. The system will convert now to a timestamp as soon as the constant is parsed, so that when the default value is needed, the time of the table creation would be used! The first two forms will not be evaluated until the default value is used, because they are function calls. Thus they will give the desired behavior of defaulting to the time of row insertion. http://www.postgresql.org/docs/current/interactive/functions-datetime.html Osvaldo _______________________________________________ pgbr-geral mailing list [email protected] https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral
