skip to Main Content

I have a members table with four columns.

table members.tbl_member as U {
  member_id int [pk, increment]
  date_created timestamp [not null, default: `CURRENT_DATE`]
  date_modified timestamp [not null, default: `CURRENT_DATE`]
  date_security timestamp [not null, default: `CURRENT_DATE`]
}

(create script from DbDiagram)

Every column is either a auto increment primary key, or has a default value.

I want to be able to trigger an insertion on this row, and return the inserted row, but to do this I don’t need or want to insert any values for any timestamp as the that is handled by the defaults.

INSERT INTO members.tbl_member
       VALUES (nothing!)
       RETURNING 
            member_id AS MemberID,
            date_created AS DateCreated, 
            date_modified AS DateModified,
            date_security AS DateSecurity

How can I do this?

2

Answers


  1. You can use DEFAULT for this:

    INSERT INTO members.tbl_member(date_created) -- you could mention all columns
    VALUES (DEFAULT) -- if needed, mention the others as well
    RETURNING 
        member_id AS MemberID,
        date_created AS DateCreated, 
        date_modified AS DateModified,
        date_security AS DateSecurity;
    
    Login or Signup to reply.
  2. use default values

    INSERT INTO members.tbl_member 
    DEFAULT VALUES
    RETURNING 
        member_id AS MemberID,
        date_created AS DateCreated, 
        date_modified AS DateModified,
        date_security AS DateSecurity
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search