By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,514 Members | 836 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,514 IT Pros & Developers. It's quick & easy.

Could my postgres database be corrupted?

P: n/a

I wanted to get the primary keys' column names and data types for a
particular table created. Although I only created one primary key
involving 2 columns for the table, my select query below return all
the column. Below is the screenshots. I'm on Linux Slackware v9.0.0
kernel v2.4.21.

I'm still quite new with postgreSQL so I'll be grateful if you can
point out a better way to execute this query. The reason I'm doing
this is to create a way to query a underlying table given just its
tablename so that i can dynamically use it in my program.

Thank you!

eve=# CREATE TABLE films (
eve(# code CHAR(5),
eve(# title VARCHAR(40),
eve(# did DECIMAL(3),
eve(# date_prod DATE,
eve(# kind VARCHAR(10),
eve(# CONSTRAINT code_title PRIMARY KEY(code,title)
eve(# );
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
'code_title' for
table 'films'
eve=# SELECT c.attname, d.typname FROM
eve-# pg_class a, pg_constraint b,
eve-# pg_attribute c, pg_type d
eve-# WHERE b.conrelid=a.relfilenode
eve-# AND a.relfilenode=b.conrelid
eve-# AND c.attrelid=a.relfilenode
eve-# AND c.attnum>0
eve-# AND d.typelem=c.atttypid
eve-# AND a.relname='films'
eve-# AND b.contype='p';
attname | typname
code | _bpchar
kind | _varchar
title | _varchar
date_prod | _date
len | _interval
did | _numeric
(6 rows)
Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.