0

当我执行以下插入查询时:

insert into FEED_STAGING_GOOD_TRADE (JOBEXECUTIONID, STAGINGID, ROWNUMBER, system, traderef, mtmvaluation, mtmvaluationccy, prcmtmquality, prcdate) 
values (64, NEXTVAL('FEED_STAGING_TRADE_SEQ') ,2,'RMS','TRD3',1.11111111E8,'USD',100.0,'2011-12-09 +00'::timestamp)

我得到以下输出:

ERROR: null value in column "tradestagingid" violates not-null constraint
  Detail: Failing row contains (46, 64, null, 2, null, null, null, RMS, null, null, TRD3, null, null, null, null, null, null, null, null, null, null, null, null, 111111111, USD, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 100, 2011-12-09 00:00:00, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null).

应该由NEXTVAL函数结果填充的第三列被发送为空值,这违反了某个非空值约束。

但是,当我NEXTVAL像这样独立执行时:

select NEXTVAL('FEED_STAGING_TRADE_SEQ');

该函数返回正确的值,如下图所示:

下一个瓦尔

4

1 回答 1

3

您的插入为 column 提供了一个值stagingid,但不是为 column tradestagingid(错误消息所指)

您的 INSERT 语句甚至没有列出名为的列tradestagingid,因此将使用该列的默认值。

正如您似乎期望tradestagingid用序列值填充的那样,您需要更改 INSERT 的列列表并使用tradestagingid而不是stagingid. 或者更好:将其定义为标识列,以便自动填充。

于 2021-10-21T11:18:11.263 回答