Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to trigger INSERT with no values into PostgreSQL table?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading