Re:

From: Igor Korot <ikorot01(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re:
Date: 2017-07-20 03:13:10
Message-ID: CA+FnnTz+WMTpW=bAm5Q4Hj1w+eHOkeEHRzvEdWy3+Hr-KaxhDw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi, ALL

On Thu, May 11, 2017 at 6:47 PM, Adrian Klaver
<adrian(dot)klaver(at)aklaver(dot)com> wrote:
> On 05/11/2017 07:26 AM, Igor Korot wrote:
>>
>> Adrian et al,
>>
>> On Thu, May 11, 2017 at 9:54 AM, Adrian Klaver
>> <adrian(dot)klaver(at)aklaver(dot)com> wrote:
>>>
>>> On 05/11/2017 06:24 AM, Igor Korot wrote:
>
>
>> Thank you.
>> Will take a look and modify to use in my program.
>>
>> I presume I'm allowed to do that, right?
>
>
> Yes.

I'm posting this hoping that I will save some time to someone else.

Here is the query I came up with:

SELECT DISTINCT ordinal_position, column_name, data_type,
character_maximum_length, character_octet_length, numeric_precision,
numeric_precision_radix, numeric_scale, is_nullable, column_default,
CASE WHEN column_name IN (SELECT ccu.column_name FROM
information_schema.constraint_column_usage ccu,
information_schema.table_constraints tc WHERE ccu.constraint_name =
tc.constraint_name AND tc.constraint_type = 'PRIMARY KEY' AND
ccu.table_name = $2) THEN 'YES' ELSE 'NO' END AS is_pk FROM
information_schema.columns col, information_schema.table_constraints
tc WHERE tc.table_schema = col.table_schema AND tc.table_name =
col.table_name AND col.table_schema = $1 AND col.table_name = $2 ORDER
BY ordinal_position;

Is there a better way to do that? I don't mind using Postgres-only solution.

Thank you.

BTW, is there a difference between query a real tables or query a view?

>
>
>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com

In response to

  • Re: at 2017-05-11 22:47:57 from Adrian Klaver

Browse pgsql-general by date

  From Date Subject
Next Message Paul Jungwirth 2017-07-20 03:47:19 Re: How to stop array_to_json from interpolating column names that weren't there
Previous Message Tom Lane 2017-07-20 03:01:55 Re: How to stop array_to_json from interpolating column names that weren't there