-1

我正在尝试在 PostgreSQL 数据库中运行以下 DML 语句:

INSERT INTO HMS_RESERVE_CANCEL_DTL
(DIVISION_CODE,         
  UNIT_CODE,            
  RESERVATION_NO,       
  RESERVATION_DATE,     
  CANCELLATION_NO,
  CANCELLATION_DATE,
  CANCELLED_AT_UNIT,
  CANCELLATION_AMOUNT,
  CANCELLED_BY,
  CANCELLATION_REASON,
  REFUND_AMOUNT,
  POSTED_TO_FAS,
  CANCEL_PER,
  room_type,
  no_of_rooms,
  taxes ) 
values(
  '103',
  '10303',
  'GHA1314HTLRS000157',
  case trim('') when trim('08-05-2013') then null else to_date('08-05-2013','DD-MM-YYYY HH24:MI:SS') end,
  'GHA1314HTLCL000002',
  current_date,
  '10303',
  5200.0,
  '001721',
  'my parsanal',
  '53260.00',
  'N',
  10.0,
  '02',
  '10',
  '10320.0')

上面的语句开始但很快就失败了,并出现以下错误消息:

ERROR: numeric field overflow
SQL state: 22003
Detail: The absolute value is greater than or equal to 10^4 for field with precision 6, scale 2.

请帮助我摆脱这个错误(或者至少指出我正确的方向)。我的表 ( hms_rserve_cancel_dtl) 的表结构如下:

CREATE TABLE hms_reserve_cancel_dtl
(
  division_code character varying(3) NOT NULL,
  unit_code character varying(5) NOT NULL,
  reservation_no character varying(20) NOT NULL,
  reservation_date date NOT NULL,
  cancellation_no character varying(20) NOT NULL,
  cancellation_date date NOT NULL,
  cancelled_at_unit character varying(15) NOT NULL,
  cancellation_amount numeric(7,2),
  cancelled_by character varying(35),
  cancellation_reason character varying(200),
  refund_amount numeric(7,2),
  posted_to_fas character(1) DEFAULT 'N'::bpchar,
  posted_date date,
  remarks character varying(200),
  status character(1) DEFAULT 'A'::bpchar,
  cancel_per numeric(7,2),
  room_type character varying(2),
  no_of_rooms character varying(2),
  refund_status character(1),
  refunded_date date,
  taxes numeric(6,2) DEFAULT 0.00,
  CONSTRAINT hms_reserve_cancel_dtl_div_unit_code_fkey FOREIGN KEY (division_code, unit_code)
      REFERENCES aptdc_units_mst (division_code, unit_code) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT hms_reserve_cancel_dtl_reservation_no_fkey FOREIGN KEY (reservation_no, room_type)
      REFERENCES hms_reservation_mst (reservation_no, room_type) MATCH SIMPLE
      ON UPDATE RESTRICT ON DELETE RESTRICT
) 
WITHOUT OIDS;
ALTER TABLE hms_reserve_cancel_dtl OWNER TO postgres;
GRANT ALL ON TABLE hms_reserve_cancel_dtl TO postgres;
4

3 回答 3

2

您的税款字段设计为 numeric(6, 2),这意味着总共 6 位数字。小数点前4,小数点后2。您提供的值在小数点前有 5 位数字,因此不适合。

于 2013-06-05T05:49:07.340 回答
1

PostgreSQL 文档:

数字的小数位数是小数部分中小数位数的计数,位于小数点右侧。数字的精度是整数中有效位数的总和,即小数点两边的位数。所以数字 23.5141 的精度为 6,小数位数为 4。

例如10123.435不适合numeric(4,2)

create table tmp (
   a numeric (8,5)
   );

/* ok */ insert into tmp values (123.12345); 
/* ok */ insert into tmp values (1.1); 
-- this will result in 1.12346, because precicion is set to 5!
insert into tmp values (1.123456); 

/* owerflow */ insert into tmp values (1000); 
-- because of number gets rounded to 5 decimal numbers:
/* owerflow */ insert into tmp values (999.99999999999999999999);  
于 2013-06-05T05:48:36.253 回答
1

您已将税款定义为最多 6 位数字,其中 2 在小数部分中,这意味着 9999.99 是您可以插入的最大值。在您的插入中,您尝试插入 10320.0,这对于该列来说太大了。

于 2013-06-05T05:49:22.903 回答