sanitize id computation
authorMichael Wallner <mike@php.net>
Wed, 11 Dec 2013 21:28:01 +0000 (22:28 +0100)
committerMichael Wallner <mike@php.net>
Wed, 11 Dec 2013 21:28:01 +0000 (22:28 +0100)
lib/pq/Gateway/Table/Relations.php

index 7ad5326a84931c84f7fe1c8e40bcc747ad48c913..3e4d7fbd8280a622d352ff1e9e607c3b3fe74fc9 100644 (file)
@@ -6,11 +6,15 @@ use \pq\Gateway\Table;
 
 const RELATION_SQL = <<<SQL
 select
-        substring(att1.attname from '^.*(?=_'||att2.attname||'$)') as "id"
-       ,cl1.relname                                                as "foreignTable"
-    ,att1.attname                                               as "foreignColumn"
-       ,cl2.relname                                                as "referencedTable"
-    ,att2.attname                                               as "referencedColumn"
+        case att1.attname
+        when att2.attname
+               then att1.attname
+               else substring(att1.attname from '^.*(?=_'||att2.attname||'$)')
+        end          as "id"
+       ,cl1.relname  as "foreignTable"
+       ,att1.attname as "foreignColumn"
+       ,cl2.relname  as "referencedTable"
+       ,att2.attname as "referencedColumn"
 from
      pg_constraint co
     ,pg_class      cl1