From: Igor Korot <ikorot01(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject:
Date: 2017-05-07 04:43:46
Message-ID: CA+FnnTzb+x6nh=RhwL6B0=vnj6w9sTwn2jLD4YGGQA5Z3u5KbQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,
I'm trying to retrieve an information about the table. Query is below:

SELECT cols.column_name, cols.data_type,
cols.character_maximum_length, cols.character_octet_length,
cols.numeric_precision, cols.numeric_precision_radix,
cols.numeric_scale, cols,column_default, cols.is_nullable,
table_cons.constraint_type, cols.ordinal_position FROM
information_schema.columns AS cols,
information_schema.table_constraints AS table_cons WHERE
table_cons.constraint_schema = cols.table_schema AND
table_cons.table_name = cols.table_name AND cols.table_schema =
'public' AND cols.table_name = 'abcatcol' ORDER BY
cols.ordinal_position ASC;

For some reason it returns me every column multiplied instead of
giving me the column information only once and whether the field is
part of the constraint (PRIMARY KEY, FOREIGN KEY or CHECK).

It's been some time since I tried to write a big query but I think I
did it right.
And still got wrong results.

Even adding DISTINCT doesn't help.

What am I doing wrong?

Since I'm using libpq + C++ I can do multiple queries, but I thought
getting it in one shot would be preferable - less db hit.

Thank you for the help.

Responses

  • Re: at 2017-05-07 10:02:10 from Andreas Kretschmer
  • Re: at 2017-05-07 11:57:46 from David Rowley

Browse pgsql-general by date

  From Date Subject
Next Message Christoph Moench-Tegeder 2017-05-07 06:20:29 Re: Where is the error?
Previous Message Igor Korot 2017-05-07 02:23:54 Re: Sample in documentation