| From: | "jose' soares" <sferac(at)bo(dot)nettuno(dot)it> |
|---|---|
| To: | strawman(at)plexi(dot)com |
| Cc: | General Postgres List <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: [GENERAL] timestamps |
| Date: | 1999-02-24 14:39:32 |
| Message-ID: | 36D40F24.1D57DFC1@bo.nettuno.it |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
strawman(at)plexi(dot)com ha scritto:
> I'm trying to create a column that defaults to the current time and date. I
> tried the SQLServer like syntax below but potgresql choked:
>
> CREATE TABLE clicks (
> avo_userid varchar (10) NOT NULL ,
> link_id int NOT NULL ,
> the_time timestamp NOT NULL CONSTRAINT df_now DEFAULT (timestamp('now'))
> );
> NOTICE: there is more than one function named "timestamp"
> NOTICE: that satisfies the given argument types. you will have to
> NOTICE: retype your query using explicit typecasts.
> ERROR: function timestamp(unknown) does not exist
>
> Is "timestamp" not both a type and a function? How can I look it up?
>
>
You can create table like:
CREATE TABLE clicks (
userid varchar(10) not null,
links int not null,
df_time timestamp constraint df_now DEFAULT current_timestamp
);
but remember in such case you can insert a value to df_time column different
than current timestamp.
If you want to avoid this you have to create a trigger (see attached example).
--
>
> And one more question: How does one construct a foreign key relationship in
> postgres?
>
> Thanks for any help.
Foreign key is not yet implemented but you may use triggers (See attached
example).
NB: You need v6.4.? to use examples.
--
- Jose' -
"No other success in life can compensate for failure in the home" (David O.
McKay)
| Attachment | Content-Type | Size |
|---|---|---|
| version.sql | text/plain | 632 bytes |
| trigger.sql | text/plain | 2.8 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Todd Graham Lewis | 1999-02-24 15:09:35 | Re: [HACKERS] RE: [GENERAL] Transaction logging |
| Previous Message | Valerio Santinelli | 1999-02-24 14:26:23 | How to cast a boolean into an int2 ? |