Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/sql/src/modules/type-mapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ describe('cross-dialect type translation', () => {

it('Oracle → Postgres', () => {
expect(xlate(oracle, pg, 'VARCHAR2(100)').sql).toBe('varchar(100)');
expect(xlate(oracle, pg, 'NUMBER(10,0)').sql).toBe('integer');
// NUMBER(p,0): width picks the integer family (int32 / int64 / decimal).
expect(xlate(oracle, pg, 'NUMBER(9,0)').sql).toBe('integer');
expect(xlate(oracle, pg, 'NUMBER(10,0)').sql).toBe('bigint');
expect(xlate(oracle, pg, 'NUMBER(18,0)').sql).toBe('bigint');
expect(xlate(oracle, pg, 'NUMBER(19,0)').sql).toBe('numeric(19,0)');
expect(xlate(oracle, pg, 'NUMBER(38,0)').sql).toBe('numeric(38,0)');
expect(xlate(oracle, pg, 'NUMBER(10,2)').sql).toBe('numeric(10,2)');
expect(xlate(oracle, pg, 'CLOB').sql).toBe('text');
});
Expand Down
14 changes: 12 additions & 2 deletions packages/sql/src/providers/oracle/oracle.sql-dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@ import { makeDialectTypeFns, plain, sized, sizedOr, decimalAs, warn } from '../.
const types = makeDialectTypeFns({
label: 'Oracle',
parseMap: {
// NUMBER(p,0) is an integer; NUMBER(p,s>0) or bare NUMBER is decimal
number: (tok) => (tok.scale && tok.scale > 0 ? 'decimal' : tok.precision !== undefined ? 'integer' : 'decimal'),
// NUMBER(p,s>0) / bare NUMBER / NUMBER(p) → decimal. NUMBER(p,0) is an
// integer-scaled value, but precision decides the family: p≤9 fits int32,
// p≤18 fits int64, anything wider must stay decimal. Mapping every
// NUMBER(p,0) to `integer` used to emit Postgres/MySQL `integer`/`int` for
// NUMBER(19,0) and NUMBER(38,0) — silent narrowing on cross-dialect migrate.
number: (tok) => {
if ((tok.scale ?? 0) > 0) return 'decimal';
if (tok.precision === undefined) return 'decimal';
if (tok.precision <= 9) return 'integer';
if (tok.precision <= 18) return 'bigint';
return 'decimal';
},
integer: 'integer',
int: 'integer',
smallint: 'integer',
Expand Down
Loading