@@ -5,6 +5,73 @@ import { QuoteUtils } from './utils/quote-utils';
55import { ListUtils } from './utils/list-utils' ;
66import * as t from '@pgsql/types' ;
77
8+ /**
9+ * List of real PostgreSQL built-in types as they appear in pg_catalog.pg_type.typname.
10+ * These are stored in lowercase in PostgreSQL system catalogs.
11+ * Use these for lookups, validations, or introspection logic.
12+ */
13+
14+ const pgCatalogTypes = [
15+ // Integers
16+ 'int2' , // smallint
17+ 'int4' , // integer
18+ 'int8' , // bigint
19+
20+ // Floating-point & numeric
21+ 'float4' , // real
22+ 'float8' , // double precision
23+ 'numeric' , // arbitrary precision (aka "decimal")
24+
25+ // Text & string
26+ 'varchar' , // variable-length string
27+ 'char' , // internal one-byte type (used in special cases)
28+ 'bpchar' , // blank-padded char(n)
29+ 'text' , // unlimited string
30+ 'bool' , // boolean
31+
32+ // Dates & times
33+ 'date' , // calendar date
34+ 'time' , // time without time zone
35+ 'timetz' , // time with time zone
36+ 'timestamp' , // timestamp without time zone
37+ 'timestamptz' , // timestamp with time zone
38+ 'interval' , // duration
39+
40+ // Binary & structured
41+ 'bytea' , // binary data
42+ 'uuid' , // universally unique identifier
43+
44+ // JSON & XML
45+ 'json' , // textual JSON
46+ 'jsonb' , // binary JSON
47+ 'xml' , // XML format
48+
49+ // Money & bitstrings
50+ 'money' , // currency value
51+ 'bit' , // fixed-length bit string
52+ 'varbit' , // variable-length bit string
53+
54+ // Network types
55+ 'inet' , // IPv4 or IPv6 address
56+ 'cidr' , // network address
57+ 'macaddr' , // MAC address (6 bytes)
58+ 'macaddr8' // MAC address (8 bytes)
59+ ] ;
60+
61+
62+ /**
63+ * Parser-level type aliases accepted by PostgreSQL SQL syntax,
64+ * but not present in pg_catalog.pg_type. These are resolved to
65+ * real types during parsing and never appear in introspection.
66+ */
67+ const pgCatalogTypeAliases : [ string , string [ ] ] [ ] = [
68+ [ 'numeric' , [ 'decimal' , 'dec' ] ] ,
69+ [ 'int4' , [ 'int' , 'integer' ] ] ,
70+ [ 'float8' , [ 'float' ] ] ,
71+ [ 'bpchar' , [ 'character' ] ] ,
72+ [ 'varchar' , [ 'character varying' ] ]
73+ ] ;
74+
875export interface DeparserOptions {
976 newline ?: string ;
1077 tab ?: string ;
@@ -1609,10 +1676,6 @@ export class Deparser implements DeparserVisitor {
16091676 }
16101677
16111678 if ( catalog === 'pg_catalog' ) {
1612- const builtinTypes = [ 'int2' , 'int4' , 'int8' , 'float4' , 'float8' , 'numeric' , 'decimal' ,
1613- 'varchar' , 'char' , 'bpchar' , 'text' , 'bool' , 'date' , 'time' , 'timestamp' ,
1614- 'timestamptz' , 'interval' , 'bytea' , 'uuid' , 'json' , 'jsonb' ] ;
1615-
16161679 let typeName = `${ catalog } .${ type } ` ;
16171680
16181681 if ( type === 'bpchar' && args ) {
0 commit comments