Search Postgresql Archives

Re: Querying database for table pk - better way?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/5/07, Josh Trutwin <josh@xxxxxxxxxxxxxxxxxxx> wrote:
> I have a php application that needs to query the PK of a table - I'm
> currently using this from the information_schema views:

try this:
CREATE OR REPLACE VIEW PKEYS AS
	SELECT nspname as schema, c2.oid as tableoid, c2.relname as table,
	  substring(pg_catalog.pg_get_indexdef(i.indexrelid, 0, true) from
E'\\((.*)\\)')
	FROM pg_catalog.pg_class c, pg_catalog.pg_class c2,
pg_catalog.pg_index i, pg_namespace n
	WHERE c.oid = i.indrelid AND i.indexrelid = c2.oid AND c.relkind = 'r'
	  AND i.indisprimary AND c.relnamespace = n.oid
	ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname;

merlin

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux