cancel
Showing results for 
Search instead for 
Did you mean: 

CDS Defaults in Type

former_member185490
Participant
0 Kudos

I have a type declared in CDS like:

   type AuditT {

        CreatedBy : sMedDesc;

        CreatedDt : UTCDateTime;

        UpdatedBy : sMedDesc;

        UpdatedDt : UTCDateTime;

   };

I want to set default date to CreatedDt as current datetime so that when a record is inserted if no value is passed, it should insert with default current datetime?

Any idea?

Also is there a way to specify a sequence to specific column so that on each insert it increments the value based on sequence.

I can not find these features in CDS.

Appreciate your thoughts.

Regards,

Naresh G

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Sequence is not there yet in CDS , but it is possible with .hdbsequence artifact

and to default date field, did you try like below?

   type AuditT {

        CreatedBy : sMedDesc;

        CreatedDt : UTCDateTime default CURRENT_UTCTIMESTAMP;

        UpdatedBy : sMedDesc;

        UpdatedDt : UTCDateTime;

   };

former_member185490
Participant
0 Kudos

Yes i tried that already and it does not work. I even tried with current_timestamp or current_date. This is the error i get

"CURRENT_UTCTIMESTAMP" is a reserved SQL KEYWORD, and cannot be used as a name

Thanks for your response.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I'll say up front that my system is running an early version of SPS 10 and there will be lots of extensions to CDS in SPS 10 for better integration of standard SQL functions.  That said, I'm able to use the CURRENT_UTCTIMESTAMP as the default just fine in my system. Looks like this is a feature which is coming soon.

namespace playground;

@Schema: 'PLAYGROUND'

context scn {

    @Catalog.tableType: #COLUMN

    entity Users {

        key ID      : Integer;

        Name        : String(20) not null;

       

        updatedDt: UTCDateTime default CURRENT_UTCTIMESTAMP;

    };

};

former_member185490
Participant
0 Kudos

Thank you Thomas. Appreciate your inputs