@@ -400,8 +400,7 @@ ORDER BY attnum
400400 else
401401 {
402402 column . DefaultValueSql = defaultValueSql ;
403- column . DefaultValue = ParseClrDefault ( systemTypeName , defaultValueSql ) ;
404- AdjustDefaults ( column , systemTypeName ) ;
403+ column . DefaultValue = ParseDefaultValueSql ( systemTypeName , defaultValueSql ) ;
405404 }
406405
407406 // Identify IDENTITY columns, as well as SERIAL ones.
@@ -503,7 +502,7 @@ ORDER BY attnum
503502 }
504503 }
505504
506- private static object ? ParseClrDefault ( string dataTypeName , string ? defaultValueSql )
505+ private static object ? ParseDefaultValueSql ( string systemTypeName , string ? defaultValueSql )
507506 {
508507 defaultValueSql = defaultValueSql ? . Trim ( ) ;
509508
@@ -514,22 +513,23 @@ ORDER BY attnum
514513
515514 while ( defaultValueSql . StartsWith ( '(' ) && defaultValueSql . EndsWith ( ')' ) )
516515 {
517- defaultValueSql = defaultValueSql . Substring ( 1 , defaultValueSql . Length - 2 ) . Trim ( ) ;
516+ defaultValueSql = defaultValueSql [ 1 .. ^ 1 ] . Trim ( ) ;
518517 }
519518
520- return dataTypeName switch
519+ return systemTypeName switch
521520 {
522521 "bool" or "boolean" => defaultValueSql switch
523522 {
524523 "true" or "yes" or "on" or "1" => true ,
525524 "false" or "no" or "off" or "0" => false ,
526525 _ => null
527526 } ,
527+
528528 "smallint" or "int2" => short . TryParse ( defaultValueSql , CultureInfo . InvariantCulture , out var @short ) ? @short : null ,
529529 "integer" or "int" or "int4" => int . TryParse ( defaultValueSql , CultureInfo . InvariantCulture , out var @int ) ? @int : null ,
530530 "bigint" or "int8" => long . TryParse ( defaultValueSql , CultureInfo . InvariantCulture , out var @long ) ? @long : null ,
531531
532- "real" or "float4" => float . TryParse ( defaultValueSql , CultureInfo . InvariantCulture , out var @float ) ? @float : null ,
532+ "real" or "float4" => float . TryParse ( defaultValueSql , CultureInfo . InvariantCulture , out var @float ) ? @float : null ,
533533 "double precision" or "float8" => double . TryParse ( defaultValueSql , CultureInfo . InvariantCulture , out var @double ) ? @double : null ,
534534 "numeric" or "decimal" => decimal . TryParse ( defaultValueSql , CultureInfo . InvariantCulture , out var @decimal ) ? @decimal : null ,
535535
@@ -1238,55 +1238,7 @@ nspname NOT IN ({internalSchemas})
12381238
12391239 #endregion
12401240
1241- #region Configure default values
1242-
1243- /// <summary>
1244- /// Configures the default value for a column.
1245- /// </summary>
1246- /// <param name="column">The column to configure.</param>
1247- /// <param name="systemTypeName">The type name of the column.</param>
1248- private static void AdjustDefaults ( DatabaseColumn column , string systemTypeName )
1249- {
1250- var defaultValue = column . DefaultValueSql ;
1251- if ( defaultValue is null or "(NULL)" )
1252- {
1253- column . DefaultValueSql = null ;
1254- return ;
1255- }
1256-
1257- if ( column . IsNullable )
1258- {
1259- return ;
1260- }
1261-
1262- if ( defaultValue == "0" )
1263- {
1264- if ( systemTypeName is "float4" or "float8" or "int2" or "int4" or "int8" or "money" or "numeric" )
1265- {
1266- column . DefaultValueSql = null ;
1267- return ;
1268- }
1269- }
1270-
1271- if ( defaultValue is "0.0" or "'0'::numeric" )
1272- {
1273- if ( systemTypeName is "numeric" or "float4" or "float8" or "money" )
1274- {
1275- column . DefaultValueSql = null ;
1276- return ;
1277- }
1278- }
1279-
1280- if ( systemTypeName == "bool" && defaultValue == "false"
1281- || systemTypeName == "date" && defaultValue == "'0001-01-01'::date"
1282- || systemTypeName == "timestamp" && defaultValue == "'1900-01-01 00:00:00'::timestamp without time zone"
1283- || systemTypeName == "time" && defaultValue == "'00:00:00'::time without time zone"
1284- || systemTypeName == "interval" && defaultValue == "'00:00:00'::interval"
1285- || systemTypeName == "uuid" && defaultValue == "'00000000-0000-0000-0000-000000000000'::uuid" )
1286- {
1287- column . DefaultValueSql = null ;
1288- }
1289- }
1241+ #region SequenceInfo
12901242
12911243 private static SequenceInfo ReadSequenceInfo ( DbDataRecord record , Version postgresVersion )
12921244 {
0 commit comments