mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-14 18:12:05 +08:00
PostgreSQL: Query pg_constraint + pg_attribute instead of IS.TABLE_CONSTRAINTS + IS.KEY_COLUMN_USAGE for keys and their column names. See http://www.heidisql.com/forum.php?t=16213
This commit is contained in:
@ -2577,6 +2577,30 @@ begin
|
|||||||
Cols.Free;
|
Cols.Free;
|
||||||
|
|
||||||
// Retrieve primary and unique key details from IS
|
// Retrieve primary and unique key details from IS
|
||||||
|
// For PostgreSQL there seem to be privilege problems in IS.
|
||||||
|
// See http://www.heidisql.com/forum.php?t=16213
|
||||||
|
case Parameters.NetTypeGroup of
|
||||||
|
ngPgSQL: begin
|
||||||
|
Keys := GetResults('SELECT '+QuoteIdent('c')+'.'+QuoteIdent('conname')+' AS '+QuoteIdent('CONSTRAINT_NAME')+', '+
|
||||||
|
'CASE '+QuoteIdent('c')+'.'+QuoteIdent('contype')+' '+
|
||||||
|
'WHEN '+EscapeString('c')+' THEN '+EscapeString('CHECK')+' '+
|
||||||
|
'WHEN '+EscapeString('f')+' THEN '+EscapeString('FOREIGN KEY')+' '+
|
||||||
|
'WHEN '+EscapeString('p')+' THEN '+EscapeString('PRIMARY KEY')+' '+
|
||||||
|
'WHEN '+EscapeString('u')+' THEN '+EscapeString('UNIQUE')+' '+
|
||||||
|
'END AS '+QuoteIdent('CONSTRAINT_TYPE')+', '+
|
||||||
|
QuoteIdent('a')+'.'+QuoteIdent('attname')+' AS '+QuoteIdent('COLUMN_NAME')+' '+
|
||||||
|
'FROM '+QuoteIdent('pg_constraint')+' AS '+QuoteIdent('c')+' '+
|
||||||
|
'LEFT JOIN '+QuoteIdent('pg_class')+' '+QuoteIdent('t')+' ON '+QuoteIdent('c')+'.'+QuoteIdent('conrelid')+'='+QuoteIdent('t')+'.'+QuoteIdent('oid')+' '+
|
||||||
|
'LEFT JOIN '+QuoteIdent('pg_attribute')+' '+QuoteIdent('a')+' ON '+QuoteIdent('t')+'.'+QuoteIdent('oid')+'='+QuoteIdent('a')+'.'+QuoteIdent('attrelid')+' '+
|
||||||
|
'LEFT JOIN '+QuoteIdent('pg_namespace')+' '+QuoteIdent('n')+' ON '+QuoteIdent('t')+'.'+QuoteIdent('relnamespace')+'='+QuoteIdent('n')+'.'+QuoteIdent('oid')+' '+
|
||||||
|
'WHERE c.contype IN ('+EscapeString('p')+', '+EscapeString('u')+') '+
|
||||||
|
'AND '+QuoteIdent('a')+'.'+QuoteIdent('attnum')+'=ANY('+QuoteIdent('c')+'.'+QuoteIdent('conkey')+') '+
|
||||||
|
'AND '+QuoteIdent('n')+'.'+QuoteIdent('nspname')+'='+EscapeString(Schema)+' '+
|
||||||
|
'AND '+QuoteIdent('t')+'.'+QuoteIdent('relname')+'='+EscapeString(Name)+' '+
|
||||||
|
'ORDER BY '+QuoteIdent('a')+'.'+QuoteIdent('attnum')
|
||||||
|
);
|
||||||
|
end;
|
||||||
|
else begin
|
||||||
Keys := GetResults('SELECT C.CONSTRAINT_NAME, C.CONSTRAINT_TYPE, K.COLUMN_NAME'+
|
Keys := GetResults('SELECT C.CONSTRAINT_NAME, C.CONSTRAINT_TYPE, K.COLUMN_NAME'+
|
||||||
' FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS C'+
|
' FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS C'+
|
||||||
' INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS K ON'+
|
' INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS K ON'+
|
||||||
@ -2585,6 +2609,8 @@ begin
|
|||||||
' AND '+SchemaClauseIS('K.TABLE')+
|
' AND '+SchemaClauseIS('K.TABLE')+
|
||||||
' WHERE C.CONSTRAINT_TYPE IN ('+EscapeString('PRIMARY KEY')+', '+EscapeString('UNIQUE')+')'+
|
' WHERE C.CONSTRAINT_TYPE IN ('+EscapeString('PRIMARY KEY')+', '+EscapeString('UNIQUE')+')'+
|
||||||
' ORDER BY K.ORDINAL_POSITION');
|
' ORDER BY K.ORDINAL_POSITION');
|
||||||
|
end;
|
||||||
|
end;
|
||||||
ConstraintName := '';
|
ConstraintName := '';
|
||||||
ColNames := TStringList.Create;
|
ColNames := TStringList.Create;
|
||||||
while not Keys.Eof do begin
|
while not Keys.Eof do begin
|
||||||
|
Reference in New Issue
Block a user