Thread: timestamp default current_timestamp not working

timestamp default current_timestamp not working

From
Sanjay Minni
Date:
Hi

I am not getting the timestamp value which i am expecting to be automatically inserted in the column defined: 
...
"timestamp" timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
...
(I see the above definition in pgadmin4 in the tab SQL. 
I have set it thru pgadmin4 table->properties->columns by entering CURRENT_TIMESTAMP in the default column)

why is the timestamp value not being automatically inserted by the system

with warm regards
Sanjay Minni

Re: timestamp default current_timestamp not working

From
Ron
Date:
On 12/14/21 9:36 AM, Sanjay Minni wrote:
Hi

I am not getting the timestamp value which i am expecting to be automatically inserted in the column defined: 
...
"timestamp" timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
...
(I see the above definition in pgadmin4 in the tab SQL. 
I have set it thru pgadmin4 table->properties->columns by entering CURRENT_TIMESTAMP in the default column)

why is the timestamp value not being automatically inserted by the system

We do not know exactly what you're doing,  (Always provide sample code when asking a "why doesn't this work?" question.)

--
Angular momentum makes the world go 'round.

Re: timestamp default current_timestamp not working

From
Adrian Klaver
Date:
On 12/14/21 07:36, Sanjay Minni wrote:
> Hi
> 
> I am not getting the timestamp value which i am expecting to be 
> automatically inserted in the column defined:
> ...
> "timestamp" timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
> ...
> (I see the above definition in pgadmin4 in the tab SQL.
> I have set it thru pgadmin4 table->properties->columns by entering 
> CURRENT_TIMESTAMP in the default column)
> 
> why is the timestamp value not being automatically inserted by the system

1) It is a DEFAULT value so if a value is provided in the INSERT that 
will be used.

2) DEFAULT values only apply to INSERTs not UPDATEs.

> 
> with warm regards
> Sanjay Minni


-- 
Adrian Klaver
adrian.klaver@aklaver.com



Re: timestamp default current_timestamp not working

From
Sanjay Minni
Date:
Its an insert and my insert SQL contains the column timestamp and value nil. 
Will it work if the SQL contains timestamp through value is nil

On Tue, 14 Dec, 2021, 9:20 pm Adrian Klaver, <adrian.klaver@aklaver.com> wrote:
On 12/14/21 07:36, Sanjay Minni wrote:
> Hi
>
> I am not getting the timestamp value which i am expecting to be
> automatically inserted in the column defined:
> ...
> "timestamp" timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
> ...
> (I see the above definition in pgadmin4 in the tab SQL.
> I have set it thru pgadmin4 table->properties->columns by entering
> CURRENT_TIMESTAMP in the default column)
>
> why is the timestamp value not being automatically inserted by the system

1) It is a DEFAULT value so if a value is provided in the INSERT that
will be used.

2) DEFAULT values only apply to INSERTs not UPDATEs.

>
> with warm regards
> Sanjay Minni


--
Adrian Klaver
adrian.klaver@aklaver.com

Re: timestamp default current_timestamp not working

From
Ron
Date:
Show us the code (especially since there is no value "nil" in SQL).

On 12/14/21 10:00 AM, Sanjay Minni wrote:
Its an insert and my insert SQL contains the column timestamp and value nil. 
Will it work if the SQL contains timestamp through value is nil

On Tue, 14 Dec, 2021, 9:20 pm Adrian Klaver, <adrian.klaver@aklaver.com> wrote:
On 12/14/21 07:36, Sanjay Minni wrote:
> Hi
>
> I am not getting the timestamp value which i am expecting to be
> automatically inserted in the column defined:
> ...
> "timestamp" timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
> ...
> (I see the above definition in pgadmin4 in the tab SQL.
> I have set it thru pgadmin4 table->properties->columns by entering
> CURRENT_TIMESTAMP in the default column)
>
> why is the timestamp value not being automatically inserted by the system

1) It is a DEFAULT value so if a value is provided in the INSERT that
will be used.

2) DEFAULT values only apply to INSERTs not UPDATEs.


--
Angular momentum makes the world go 'round.

Re: timestamp default current_timestamp not working

From
"David G. Johnston"
Date:
On Tuesday, December 14, 2021, Sanjay Minni <sanjay.minni@gmail.com> wrote:
Its an insert and my insert SQL contains the column timestamp and value nil. 
Will it work if the SQL contains timestamp through value is nil


If you explicitly specify NULL for the value of the column then there is no need for the system to produce a default, and thus you will see NULL when you query that record.

You can say “DEFAULT” (no quotes) though if you need to have the column name in the Insert statement but still want the default to be used.

David J.

Re: timestamp default current_timestamp not working

From
Adrian Klaver
Date:
On 12/14/21 08:00, Sanjay Minni wrote:
> Its an insert and my insert SQL contains the column timestamp and value 
> nil.
> Will it work if the SQL contains timestamp through value is nil
No nil(NULL) is a valid value for the field as you have not specified 
NOT NULL on the column. If you do add that constraint you will get an 
error with your inserts. If you want the DEFAULT to work you will need 
to not include the "timestamp"(FYI, not a good choice for a name) field 
in the INSERT.


> 
> On Tue, 14 Dec, 2021, 9:20 pm Adrian Klaver, <adrian.klaver@aklaver.com 


-- 
Adrian Klaver
adrian.klaver@aklaver.com