From 38f2cec25d0c35e1977f90a7204645d9fe5e92fd Mon Sep 17 00:00:00 2001 From: marsonshine Date: Fri, 8 Nov 2024 14:23:14 +0800 Subject: [PATCH] fix: compatibility between GENERATED and SERIAL auto-increment fields in PostgreSQL version 10 and above --- .../PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs b/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs index 16fda19a6..77cd2a828 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs @@ -30,8 +30,11 @@ namespace SqlSugar col_description(pclass.oid, pcolumn.ordinal_position) as ColumnDescription, case when pkey.colname = pcolumn.column_name then true else false end as IsPrimaryKey, - case when pcolumn.column_default like 'nextval%' - then true else false end as IsIdentity, + CASE + WHEN (current_setting('server_version_num')::INT >= 100000 AND pcolumn.is_identity = 'YES') THEN true + WHEN pcolumn.column_default LIKE 'nextval%' THEN true + ELSE false + END AS IsIdentity, case when pcolumn.is_nullable = 'YES' then true else false end as IsNullable from (select * from pg_tables where upper(tablename) = upper('{0}') and schemaname='" + schema + @"') ptables inner join pg_class pclass