pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedDEFAULT TEXT 'now'
4+ messages / 4 participants
[nested] [flat]
* DEFAULT TEXT 'now'
@ 1999-03-23 18:58 Roberto Joao Lopes Garcia <roberto@mha.com.br>
1999-03-24 07:09 ` Re: [SQL] DEFAULT TEXT 'now' Howie <caffeine@toodarkpark.org>
1999-03-24 07:10 ` Re: [SQL] DEFAULT TEXT 'now' Anatoly K. Lasareff <tolik@icomm.ru>
0 siblings, 2 replies; 4+ messages in thread
From: Roberto Joao Lopes Garcia @ 1999-03-23 18:58 UTC (permalink / raw)
To: pgsql-sql
Hi
I´m have a table like bellow:
CREATE TABLE conex (
id int4 PRIMARY KEY DEFAULT NEXTVAL('seq_conex'),
inicio datetime DEFAULT TEXT 'now',
ultimo datetime DEFAULT TEXT
'now',
.
.
.
)
insert into conex (ip) values(´200.200.200.200´)
Will result every time the same data and time for ´inicio´ and ´ultimo´!
I want to insert the current date and time. Is that code correct and the
result a bug???
Is there an way to make the DEFAULT work???
I know I can insert like:
insert into conex (ip, inicio, ultimo) values(´200.200.200.200´, ´now´, ´now´)
but I would like to use DEFAULT.
PostgreSQL 6.4 - Solaris 2.5 sparc
Thank you
Roberto
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] DEFAULT TEXT 'now'
1999-03-23 18:58 DEFAULT TEXT 'now' Roberto Joao Lopes Garcia <roberto@mha.com.br>
@ 1999-03-24 07:09 ` Howie <caffeine@toodarkpark.org>
1 sibling, 0 replies; 4+ messages in thread
From: Howie @ 1999-03-24 07:09 UTC (permalink / raw)
To: Roberto Joao Lopes Garcia <roberto@mha.com.br>; +Cc: pgsql-sql
On Tue, 23 Mar 1999, Roberto Joao Lopes Garcia wrote:
> Hi
>
> I´m have a table like bellow:
>
> CREATE TABLE conex (
> id int4 PRIMARY KEY DEFAULT NEXTVAL('seq_conex'),
>
> inicio datetime DEFAULT TEXT 'now',
> ultimo datetime DEFAULT TEXT
> 'now',
> .
> .
> .
> )
>
> insert into conex (ip) values(´200.200.200.200´)
>
> Will result every time the same data and time for ´inicio´ and ´ultimo´!
>
> I want to insert the current date and time. Is that code correct and the
> result a bug???
> Is there an way to make the DEFAULT work???
try:
...
inicido DATETIME DEFAULT NOW(),
ultimo DATETIME DEFAULT NOW(),
...
---
Howie <caffeine@toodarkpark.org> URL: http://www.toodarkpark.org
"You can change the world with a bullet in the right place"
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] DEFAULT TEXT 'now'
1999-03-23 18:58 DEFAULT TEXT 'now' Roberto Joao Lopes Garcia <roberto@mha.com.br>
@ 1999-03-24 07:10 ` Anatoly K. Lasareff <tolik@icomm.ru>
1999-03-24 16:26 ` Re: [SQL] DEFAULT TEXT 'now' Ross J. Reedstrom <reedstrm@rice.edu>
1 sibling, 1 reply; 4+ messages in thread
From: tolik@icomm.ru @ 1999-03-24 07:10 UTC (permalink / raw)
To: Roberto Joao Lopes Garcia <roberto@mha.com.br>; +Cc: pgsql-sql
>>>>> "RJLG" == Roberto Joao Lopes Garcia <roberto@mha.com.br> writes:
RJLG> Hi
RJLG> IЄm have a table like bellow:
RJLG> CREATE TABLE conex (
RJLG> id int4 PRIMARY KEY DEFAULT NEXTVAL('seq_conex'),
RJLG> inicio datetime DEFAULT TEXT 'now',
RJLG> ultimo datetime DEFAULT TEXT
RJLG> 'now',
RJLG> .
RJLG> .
RJLG> .
RJLG> )
RJLG> insert into conex (ip) values(Є200.200.200.200Є)
RJLG> Will result every time the same data and time for ЄinicioЄ and ЄultimoЄ!
You must type
inicio datetime DEFAULT TEXT now(),
^^^^^
This is the function which calls every time you insert new record. In
your case 'now' is the constant, which calculates once, when you
create the table.
--
Anatoly K. Lasareff Email: tolik@icomm.ru
Senior programmer
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] DEFAULT TEXT 'now'
1999-03-23 18:58 DEFAULT TEXT 'now' Roberto Joao Lopes Garcia <roberto@mha.com.br>
1999-03-24 07:10 ` Re: [SQL] DEFAULT TEXT 'now' Anatoly K. Lasareff <tolik@icomm.ru>
@ 1999-03-24 16:26 ` Ross J. Reedstrom <reedstrm@rice.edu>
0 siblings, 0 replies; 4+ messages in thread
From: Ross J. Reedstrom @ 1999-03-24 16:26 UTC (permalink / raw)
To: pgsql-sql
Anatoly K. Lasareff wrote:
>
> >>>>> "RJLG" == Roberto Joao Lopes Garcia <roberto@mha.com.br> writes:
>
>> <snipped problem with using default 'now'>
> <snipped description of using now() instead>
What version of postgresql are you all using? I tried RJLG's example
code with 6.4.2, and it worked - I got different times at each insert,
so the default 'now' was being calculated at insertion time, not table
creation time. Here's what it looks like:
test2=> \d conex
Table = conex
+----------------------------------+----------------------------------+-------+
| Field | Type |
Length|
+----------------------------------+----------------------------------+-------+
| id | int4 not null default nextval (
| 4 |
| inicio | datetime default text 'now'
| 8 |
| ultimo | datetime default text 'now'
| 8 |
| ip | inet
| var |
+----------------------------------+----------------------------------+-------+
Index: conex_pkey
test2=> select * from conex;
id|inicio |ultimo
| ip
--+----------------------------+----------------------------+---------------
1|Tue Mar 23 13:40:24 1999 CST|Tue Mar 23 13:40:24 1999
CST|200.200.200.200
2|Tue Mar 23 13:40:28 1999 CST|Tue Mar 23 13:40:28 1999
CST|200.200.200.202
3|Tue Mar 23 13:40:30 1999 CST|Tue Mar 23 13:40:30 1999
CST|200.200.200.203
4|Tue Mar 23 13:41:06 1999 CST|Tue Mar 23 13:41:06 1999
CST|200.200.200.203
5|Tue Mar 23 13:41:21 1999 CST|Tue Mar 23 13:41:21 1999
CST|200.200.200.205
(5 rows)
test2=>
???
Ross
--
Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu>
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St., Houston, TX 77005
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~1999-03-24 16:26 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-03-23 18:58 DEFAULT TEXT 'now' Roberto Joao Lopes Garcia <roberto@mha.com.br>
1999-03-24 07:09 ` Howie <caffeine@toodarkpark.org>
1999-03-24 07:10 ` Anatoly K. Lasareff <tolik@icomm.ru>
1999-03-24 16:26 ` Ross J. Reedstrom <reedstrm@rice.edu>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox