Thread: 'Following' the Primary key
With '\d table' I get the columns, types and modifiers. Also the Primary key, Indexes etc are shown. But if I want to know WHAT the primary key 'is pointing to', how would I do that (ie, what is the primary key)? I saw an example now to show a foreign key on the 'Net but that's not applicable here... -- cryptographic Albanian Nazi killed Ortega SDI $400 million in gold bullion NORAD [Hello to all my fans in domestic surveillance] Delta Force Treasury Uzi FSF nitrate quiche [See http://www.aclu.org/echelonwatch/index.html for more about this]
On Thu, 2002-03-14 at 13:00, Turbo Fredriksson wrote: > With '\d table' I get the columns, types and modifiers. Also > the Primary key, Indexes etc are shown. > > But if I want to know WHAT the primary key 'is pointing to', > how would I do that (ie, what is the primary key)? Just do \d again on the key index name: bray=# \d org_contact Table "org_contact"Column | Type | Modifiers ---------+-----------------------+-----------org | character varying(10) | not nullcontact | character varying(10) |not nullrole | text | not nulladdress | integer | Primary key: org_contact_pkey Triggers: RI_ConstraintTrigger_6933120, RI_ConstraintTrigger_6933114, RI_ConstraintTrigger_6933108 bray=# \d org_contact_pkey Index "org_contact_pkey"Column | Type ---------+-----------------------org | character varying(10)contact | character varying(10) unique btree (primary key) -- Oliver Elphick Oliver.Elphick@lfix.co.uk Isle of Wight http://www.lfix.co.uk/oliver GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C "Let your light so shine before men, that they may see your good works, and glorify your Father which is in heaven." Matthew 5:16
>>>>> "Oliver" == Oliver Elphick <olly@lfix.co.uk> writes: Oliver> On Thu, 2002-03-14 at 13:00, Turbo Fredriksson wrote: >> With '\d table' I get the columns, types and modifiers.Also >> the Primary key, Indexes etc are shown. >> >> But if I want to know WHAT the primary key 'is pointingto', >> how would I do that (ie, what is the primary key)? Oliver> Just do \d again on the key index name: Oliver> bray=# \d org_contact Oliver> bray=# \d org_contact_pkey Cool. Works fine in 7.2, but not 7.1.3 (which we're running on our production systems)... Any idea how to do this on 7.1.3? -- jihad iodine subway arrangements 767 Cocaine 747 Waco, Texas [Hello to all my fans in domestic surveillance] terrorist security radar North Korea plutonium Semtex [See http://www.aclu.org/echelonwatch/index.html for more about this]
> Cool. Works fine in 7.2, but not 7.1.3 (which we're running on our > production systems)... > Any idea how to do this on 7.1.3? contact=# \d t_operation Table "t_operation"Attribute | Type | Modifier -----------+------------------------+----------------------------------------------------op_id | integer | not null default nextval('operation_id_seq'::text)op_date | date | not nullop_dpt | charactervarying(50) | op_typ | character varying(50) | op_dsc | character varying(500) | cnx_id | integer | not null Index: t_operation_pkey ^^^^^ Default primary key index contact=# \d t_operation_pkey Index "t_operation_pkey"Attribute | Type -----------+---------op_id | integer unique btree (primary key) ^^^^^^ ^^^^^^^^^^^^^ Watch for unique indices created with CREATE UNIQUE INDEX ... Cheers, -- Jean-Paul ARGUDO
Quoting Oliver Elphick <olly@lfix.co.uk>: > On Thu, 2002-03-14 at 13:28, Turbo Fredriksson wrote: > > Oliver> Just do \d again on the key index name: > > > > Oliver> bray=# \d org_contact > > Oliver> bray=# \d org_contact_pkey > > > > Cool. Works fine in 7.2, but not 7.1.3 (which we're running on our > > production systems)... > > > > Any idea how to do this on 7.1.3? > > psql -E tells me that the queries include this: I thought it was '-e', and that didn't give any output, so I never figured out this my self... > SELECT a.attname, format_type(a.atttypid, a.atttypmod), > a.attnotnull, a.atthasdef, a.attnum > FROM pg_class c, pg_attribute a > WHERE c.relname = 'org_contact_pkey' > AND a.attnum > 0 AND a.attrelid = c.oid > ORDER BY a.attnum; Works like a charm, thanx!! -- $400 million in gold bullion Soviet Saddam Hussein supercomputer Waco, Texas Iran munitions PLO explosion Cuba congress Semtex BATF Treasury NSA [See http://www.aclu.org/echelonwatch/index.html for more about this]
Turbo Fredriksson wrote: >>>>>>"Oliver" == Oliver Elphick <olly@lfix.co.uk> writes: >>>>>> > > Oliver> On Thu, 2002-03-14 at 13:00, Turbo Fredriksson wrote: > >> With '\d table' I get the columns, types and modifiers. Also > >> the Primary key, Indexes etc are shown. > >> > >> But if I want to know WHAT the primary key 'is pointing to', > >> how would I do that (ie, what is the primary key)? > > Oliver> Just do \d again on the key index name: > > Oliver> bray=# \d org_contact > Oliver> bray=# \d org_contact_pkey > > Cool. Works fine in 7.2, but not 7.1.3 (which we're running on our > production systems)... > > Any idea how to do this on 7.1.3? > See: http://www.brasileiro.net/postgres/cookbook/view-one-recipe.adp?recipe_id=36 for one possible way. Joe