@@ -637,6 +637,7 @@ bool QgsPostgresProvider::loadFields()
637
637
int fieldPrec = -1 ;
638
638
QString fieldComment ( " " );
639
639
int tableoid = result.PQftable ( i );
640
+ int attnum = result.PQftablecol ( i );
640
641
641
642
sql = QString ( " SELECT typname,typtype,typelem,typlen FROM pg_type WHERE oid=%1" ).arg ( typOid );
642
643
// just oid; needs more work to support array type
@@ -652,22 +653,19 @@ bool QgsPostgresProvider::loadFields()
652
653
QString formattedFieldType;
653
654
if ( tableoid > 0 )
654
655
{
655
- sql = QString ( " SELECT attnum, pg_catalog.format_type(atttypid,atttypmod) FROM pg_attribute WHERE attrelid=%1 AND attname =%2" )
656
- .arg ( tableoid ).arg ( quotedValue ( fieldName ) );
656
+ sql = QString ( " SELECT pg_catalog.format_type(atttypid,atttypmod) FROM pg_attribute WHERE attrelid=%1 AND attnum =%2" )
657
+ .arg ( tableoid ).arg ( quotedValue ( attnum ) );
657
658
658
659
QgsPostgresResult tresult = mConnectionRO ->PQexec ( sql );
659
- QString attnum = tresult.PQgetvalue ( 0 , 0 );
660
- formattedFieldType = tresult.PQgetvalue ( 0 , 1 );
660
+ if ( tresult.PQntuples () > 0 )
661
+ formattedFieldType = tresult.PQgetvalue ( 0 , 0 );
661
662
662
- if ( !attnum.isEmpty () )
663
- {
664
- sql = QString ( " SELECT description FROM pg_description WHERE objoid=%1 AND objsubid=%2" )
665
- .arg ( tableoid ).arg ( attnum );
663
+ sql = QString ( " SELECT description FROM pg_description WHERE objoid=%1 AND objsubid=%2" )
664
+ .arg ( tableoid ).arg ( attnum );
666
665
667
- tresult = mConnectionRO ->PQexec ( sql );
668
- if ( tresult.PQntuples () > 0 )
669
- fieldComment = tresult.PQgetvalue ( 0 , 0 );
670
- }
666
+ tresult = mConnectionRO ->PQexec ( sql );
667
+ if ( tresult.PQntuples () > 0 )
668
+ fieldComment = tresult.PQgetvalue ( 0 , 0 );
671
669
}
672
670
673
671
QVariant::Type fieldType;
0 commit comments