Re: Active Record

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Emanuel Calvo Franco <postgres(dot)arg(at)gmail(dot)com>
Cc: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: Active Record
Date: 2009-03-27 15:01:20
Message-ID: 20090327150119.GQ11993@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Emanuel Calvo Franco escribió:

> Alvaro: Se que tiene que haber pero no logro 'joinar' correctamente
> las tablas del catalogo...
> ¿cual es la consulta que trae el nombre del campo que es primary key y su
> tipo? Estuve explorando lo que utiliza psql en sus consultas pero no
> no doy en el clavo,
> que campo linkea pg_constraint y pg_attiributes?

Necesitas pg_index, no pg_constraint. Prueba así:

select
pg_attribute.attname,
format_type(pg_attribute.atttypid, pg_attribute.atttypmod)
from pg_index, pg_class, pg_attribute
where
pg_class.oid = 'foo'::regclass and
indrelid = pg_class.oid and
pg_attribute.attrelid = pg_class.oid and
pg_attribute.attnum = any(pg_index.indkey);

alvherre=# create table emanuel (calvo int, franco numeric(3, 2), primary key (calvo, franco));
NOTICE: CREATE TABLE / PRIMARY KEY creará el índice implícito «emanuel_pkey» para la tabla «emanuel»
CREATE TABLE

alvherre=# select
alvherre-# pg_attribute.attname,
alvherre-# format_type(pg_attribute.atttypid, pg_attribute.atttypmod)
alvherre-# from pg_index, pg_class, pg_attribute
alvherre-# where
alvherre-# pg_class.oid = 'public.emanuel'::regclass and
alvherre-# indrelid = pg_class.oid and
alvherre-# pg_attribute.attrelid = pg_class.oid and
alvherre-# pg_attribute.attnum = any(pg_index.indkey);

attname | format_type
---------+--------------
calvo | integer
franco | numeric(3,2)
(2 filas)

--
Alvaro Herrera http://www.amazon.com/gp/registry/5ZYLFMCVHXC
"I must say, I am absolutely impressed with what pgsql's implementation of
VALUES allows me to do. It's kind of ridiculous how much "work" goes away in
my code. Too bad I can't do this at work (Oracle 8/9)." (Tom Allison)
http://archives.postgresql.org/pgsql-general/2007-06/msg00016.php

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Emanuel Calvo Franco 2009-03-27 15:06:09 Re: Active Record
Previous Message jeison gutierrez 2009-03-27 14:53:05 Re: [pgsql-es-ayuda] Re: [pgsql-es-ayuda] Ver consultas en ejecución