如何在Postgres表的字段上设置默认日期?

时间:2017-06-25 16:14:33

标签: postgresql timestamp

如何在postgresql上添加默认日期?

我尝试getdate(),但命令出错:

ERROR: function getdate() does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might need to add explicit type casts.

发出的命令是:

Create TABLE CREATE_ORDERS (
Plot_ID VARCHAR (50) ,
USER_ID VARCHAR(50),
ORDER_ID VARCHAR(50),
TOTAL_AMOUNT float NOT NULL DEFAULT 0.000,
DOWNPAYMENT float NOT NULL DEFAULT 25000,
BALANCE_INSTALLMENT_AMOUNT float NOT NULL DEFAULT 0.000,
NO_OF_INSTALLMENTS float NOT NULL DEFAULT 12,
PURCHASE_DATE TIMESTAMP  NOT NULL DEFAULT GETDATE(),
DUE_DATE TIMESTAMP  NOT NULL DEFAULT GETDATE(),
CONSTRAINT AK_TransactionID1 UNIQUE(PLOT_ID),
CONSTRAINT AK_TransactionID2 UNIQUE(ORDER_ID),
PRIMARY KEY (PLOT_ID, ORDER_ID));

2 个答案:

答案 0 :(得分:3)

使用关键字CURRENT_TIMESTAMP代替功能GETDATE()

--Current date and time    
SELECT CURRENT_TIMESTAMP;

--Current date    
SELECT CURRENT_DATE;

--Current date and time    
SELECT NOW();

更多信息here

答案 1 :(得分:1)