timestamp default current_timestamp not working

Started by Sanjay Minniover 4 years ago7 messagesgeneral
Jump to latest
#1Sanjay Minni
sanjay.minni@gmail.com

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

#2Ron
ronljohnsonjr@gmail.com
In reply to: Sanjay Minni (#1)
Re: timestamp default current_timestamp not working

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.

#3Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Sanjay Minni (#1)
Re: timestamp default current_timestamp not working

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

#4Sanjay Minni
sanjay.minni@gmail.com
In reply to: Adrian Klaver (#3)
Re: timestamp default current_timestamp not working

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:

Show quoted text

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

#5Ron
ronljohnsonjr@gmail.com
In reply to: Sanjay Minni (#4)
Re: timestamp default current_timestamp not working

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
<mailto: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.

#6David G. Johnston
david.g.johnston@gmail.com
In reply to: Sanjay Minni (#4)
Re: timestamp default current_timestamp not working

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.

#7Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Sanjay Minni (#4)
Re: timestamp default current_timestamp not working

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