Re: Existencia de columna en tabla

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Guido Barosio <gbarosio(at)gmail(dot)com>
Cc: Eliana Gutierrez <egp1962(at)yahoo(dot)com(dot)au>, ayuda postgres <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: Existencia de columna en tabla
Date: 2007-01-08 01:41:06
Message-ID: 20070108014106.GB7810@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Guido Barosio escribió:

> SELECT a.attname,
> pg_catalog.format_type(a.atttypid, a.atttypmod),
> (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)
> FROM pg_catalog.pg_attrdef d
> WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),
> a.attnotnull, a.attnum
> FROM pg_catalog.pg_attribute a
> WHERE a.attrelid = '24588' AND a.attnum > 0 AND NOT a.attisdropped
> ORDER BY a.attnum

Tambien puedes hacerlo asi, mas facil y te evita la consulta a pg_class:

SELECT a.attname,
pg_catalog.format_type(a.atttypid, a.atttypmod),
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)
FROM pg_catalog.pg_attrdef d
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),
a.attnotnull, a.attnum
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = 'nombre-tabla'::regclass AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum

Lo otro es que el motivo para poner pg_attrdef en un subselect y no como
un JOIN es un misterio ...

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Alvaro Herrera 2007-01-08 01:55:40 Re: Ayuda!
Previous Message Alvaro Herrera 2007-01-08 01:38:18 Re: Estructura JoinType