/[pgestraier]/trunk/bin/pgest-index.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/bin/pgest-index.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 74 by dpavlin, Mon Aug 7 22:53:46 2006 UTC revision 77 by dpavlin, Tue Aug 8 11:01:00 2006 UTC
# Line 54  not needed for search. Line 54  not needed for search.
54  =item --pk id  =item --pk id
55    
56  Specify name of primary key column in SQL query. If you allready have primary  Specify name of primary key column in SQL query. If you allready have primary
57  key on table, and it consists of simgle column (compaund keys are not supported)  key on table or unique index and it consists of simgle column
58  it will be picked up automatically.  (compaund keys are not supported) it will be picked up automatically.
59    
60  If you specify value which is not unique, you will get just last occurence  If you specify value which is not unique, you will get just last occurence
61  of that item in index (which might be what you want). That's because specified  of that item in index (which might be what you want). That's because specified
# Line 156  if (! $c->{pk}) { Line 156  if (! $c->{pk}) {
156    
157          warn "# finding primary key for $table\n" if ($c->{debug});          warn "# finding primary key for $table\n" if ($c->{debug});
158    
159          $c->{pk} = $dbh->selectrow_array(qq{          my $index_fmt = qq{
160                  SELECT                  SELECT
161                          a.attname, t.typname                          a.attname, t.typname
162                  FROM pg_type t, pg_attribute a                  FROM pg_type t, pg_attribute a
163                  WHERE t.oid = a.atttypid AND attrelid = (                  WHERE t.oid = a.atttypid AND attrelid = (
164                          SELECT indexrelid                          SELECT indexrelid
165                          FROM pg_class c, pg_index i                          FROM pg_class c, pg_index i
166                          WHERE c.relname = '$table'                          WHERE c.relname = '%s'
167                                  AND c.oid = i.indrelid                                  AND c.oid = i.indrelid
168                                  AND indisprimary                                  AND %s
169                                  AND indnatts = 1                                  AND indnatts = 1
170                  )                  )
171          });          };
172    
173            $c->{pk} = $dbh->selectrow_array( sprintf($index_fmt, $table, 'indisprimary') );
174            
175            $c->{pk} ||= $dbh->selectrow_array( sprintf($index_fmt, $table, 'indisunique') );
176    
177  }  }
178    

Legend:
Removed from v.74  
changed lines
  Added in v.77

  ViewVC Help
Powered by ViewVC 1.1.26