pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
timestamp default current_timestamp not working
7+ messages / 4 participants
[nested] [flat]

* timestamp default current_timestamp not working
@ 2021-12-14 15:36 Sanjay Minni <sanjay.minni@gmail.com>
  2021-12-14 15:47 ` Re: timestamp default current_timestamp not working Ron <ronljohnsonjr@gmail.com>
  2021-12-14 15:50 ` Re: timestamp default current_timestamp not working Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 2 replies; 7+ messages in thread

From: Sanjay Minni @ 2021-12-14 15:36 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

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

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: timestamp default current_timestamp not working
  2021-12-14 15:36 timestamp default current_timestamp not working Sanjay Minni <sanjay.minni@gmail.com>
@ 2021-12-14 15:47 ` Ron <ronljohnsonjr@gmail.com>
  1 sibling, 0 replies; 7+ messages in thread

From: Ron @ 2021-12-14 15:47 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

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.

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: timestamp default current_timestamp not working
  2021-12-14 15:36 timestamp default current_timestamp not working Sanjay Minni <sanjay.minni@gmail.com>
@ 2021-12-14 15:50 ` Adrian Klaver <adrian.klaver@aklaver.com>
  2021-12-14 16:00   ` Re: timestamp default current_timestamp not working Sanjay Minni <sanjay.minni@gmail.com>
  1 sibling, 1 reply; 7+ messages in thread

From: Adrian Klaver @ 2021-12-14 15:50 UTC (permalink / raw)
  To: Sanjay Minni <sanjay.minni@gmail.com>; pgsql-general@lists.postgresql.org

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





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: timestamp default current_timestamp not working
  2021-12-14 15:36 timestamp default current_timestamp not working Sanjay Minni <sanjay.minni@gmail.com>
  2021-12-14 15:50 ` Re: timestamp default current_timestamp not working Adrian Klaver <adrian.klaver@aklaver.com>
@ 2021-12-14 16:00   ` Sanjay Minni <sanjay.minni@gmail.com>
  2021-12-14 16:06     ` Re: timestamp default current_timestamp not working Ron <ronljohnsonjr@gmail.com>
  2021-12-14 16:08     ` Re: timestamp default current_timestamp not working David G. Johnston <david.g.johnston@gmail.com>
  2021-12-14 16:10     ` Re: timestamp default current_timestamp not working Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 3 replies; 7+ messages in thread

From: Sanjay Minni @ 2021-12-14 16:00 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general@lists.postgresql.org

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
>

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: timestamp default current_timestamp not working
  2021-12-14 15:36 timestamp default current_timestamp not working Sanjay Minni <sanjay.minni@gmail.com>
  2021-12-14 15:50 ` Re: timestamp default current_timestamp not working Adrian Klaver <adrian.klaver@aklaver.com>
  2021-12-14 16:00   ` Re: timestamp default current_timestamp not working Sanjay Minni <sanjay.minni@gmail.com>
@ 2021-12-14 16:06     ` Ron <ronljohnsonjr@gmail.com>
  2 siblings, 0 replies; 7+ messages in thread

From: Ron @ 2021-12-14 16:06 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

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.

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: timestamp default current_timestamp not working
  2021-12-14 15:36 timestamp default current_timestamp not working Sanjay Minni <sanjay.minni@gmail.com>
  2021-12-14 15:50 ` Re: timestamp default current_timestamp not working Adrian Klaver <adrian.klaver@aklaver.com>
  2021-12-14 16:00   ` Re: timestamp default current_timestamp not working Sanjay Minni <sanjay.minni@gmail.com>
@ 2021-12-14 16:08     ` David G. Johnston <david.g.johnston@gmail.com>
  2 siblings, 0 replies; 7+ messages in thread

From: David G. Johnston @ 2021-12-14 16:08 UTC (permalink / raw)
  To: Sanjay Minni <sanjay.minni@gmail.com>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

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.

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: timestamp default current_timestamp not working
  2021-12-14 15:36 timestamp default current_timestamp not working Sanjay Minni <sanjay.minni@gmail.com>
  2021-12-14 15:50 ` Re: timestamp default current_timestamp not working Adrian Klaver <adrian.klaver@aklaver.com>
  2021-12-14 16:00   ` Re: timestamp default current_timestamp not working Sanjay Minni <sanjay.minni@gmail.com>
@ 2021-12-14 16:10     ` Adrian Klaver <adrian.klaver@aklaver.com>
  2 siblings, 0 replies; 7+ messages in thread

From: Adrian Klaver @ 2021-12-14 16:10 UTC (permalink / raw)
  To: Sanjay Minni <sanjay.minni@gmail.com>; pgsql-general@lists.postgresql.org

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





^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2021-12-14 16:10 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-12-14 15:36 timestamp default current_timestamp not working Sanjay Minni <sanjay.minni@gmail.com>
2021-12-14 15:47 ` Ron <ronljohnsonjr@gmail.com>
2021-12-14 15:50 ` Adrian Klaver <adrian.klaver@aklaver.com>
2021-12-14 16:00   ` Sanjay Minni <sanjay.minni@gmail.com>
2021-12-14 16:06     ` Ron <ronljohnsonjr@gmail.com>
2021-12-14 16:08     ` David G. Johnston <david.g.johnston@gmail.com>
2021-12-14 16:10     ` Adrian Klaver <adrian.klaver@aklaver.com>

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