SQL Fiddle
PostgreSQL 9.6 Schema Setup:
CREATE TABLE foo
(
id serial primary key
, "bar" varchar(1)
, created_by text NOT NULL DEFAULT current_user
, created_at timestamp DEFAULT current_timestamp
)
;
INSERT INTO foo
("bar")
VALUES
('a'),
('b'),
('c')
;
Query 1:
select *
from foo
Results:
| id | bar | created_by | created_at |
|----|-----|---------------|-----------------------------|
| 1 | a | user_17_3a66a | 2017-11-04T05:05:18.161681Z |
| 2 | b | user_17_3a66a | 2017-11-04T05:05:18.161681Z |
| 3 | c | user_17_3a66a | 2017-11-04T05:05:18.161681Z |
current_useryou can usecreate_by text NOT NULL DEFAULT current_user