Home > Archive > PostgreSQL Discussion > May 2005 > Primary key column numbers...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Primary key column numbers...
Justin Tocci

2005-05-31, 8:24 pm

What I'm trying to do is
IF the relation given is a TABLE, give the primary key column numbers.
IF the relation is a VIEW, just give an array with a '1' in it.
ELSE NULL.

Later I'll put in some hocus-pocus to be more intelligent about VIEWs
but right now this would do me fine.

I've read the docs on arrays and such, I just can't seem to put
together nor cast an array that's compatible with int2vector. There
was some notice to look at contrib/array but that has been removed in
version 8, which is what I'm using.

This is what I have so far.

SELECT indkey
FROM (SELECT relname, indkey
FROM pg_catalog.pg_index join pg_catalog.pg_class
ON pg_index.indrelid = pg_class.oid
WHERE indisprimary=true
UNION
SELECT viewname, ('& #123;1}')::int2vecto
r[] as indkey
FROM pg_catalog.pg_views ) t
WHERE relname = '????'

Result: ERROR: UNION/INTERSECT/EXCEPT could not convert type
int2vector[] to int2vector

Any help here would be appreciated.

justin tocci
fort worth, tx

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com