Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lHIzw-0002Km-KN for pgsql-performance@arkaria.postgresql.org; Wed, 03 Mar 2021 04:20:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lHIzv-0004h1-EO for pgsql-performance@arkaria.postgresql.org; Wed, 03 Mar 2021 04:20:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lHIzv-0004gu-2E for pgsql-performance@lists.postgresql.org; Wed, 03 Mar 2021 04:20:31 +0000 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lHIzr-0008Nn-VT for pgsql-performance@lists.postgresql.org; Wed, 03 Mar 2021 04:20:30 +0000 Received: by mail-il1-x132.google.com with SMTP id h18so20147868ils.2 for ; Tue, 02 Mar 2021 20:20:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=H3mrvywutY2ru4AMwFD8Ljcor5zr9IvT9rl3S9z0Gug=; b=oxwTTbdNklXv4KAa8mDUkmO9Sr494w2uNw46+w5ZhsUfnxzDxjNxjKobEfD6+JPRqz TyRrWcNrb3KbCd6M9nP410bp43xj5+rWtOMkQajGi1HI/ky+qaNFTxA0MtanO3mHML7O hqyY+MuhKfqrUn9FRWnhy9PHAv4bMdZwY7zHY8DVun8gNAuhVtjvYQhcviNcltOoIwzo 8Mw+J1Lr1kn66bbs8Xz0Ce+y6Ddag+GDCETjY5TGXzYKFL/QpFHc1goTe6p+6RrZGu/a /B7PqiO2pNpQIGgGlw+JD/jdVUvr5I8E6mgaDtHGxEJaYuTJFNllRhX4A5LY4hSmbv+U Lm5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=H3mrvywutY2ru4AMwFD8Ljcor5zr9IvT9rl3S9z0Gug=; b=RmBsSi3i7vzSAC2m5AyiNcKawMzRA9qrCt5tWDA01LwNwNZQMpvnAj01Rbc8Ri8P2k oRHSX+tIZSULiVe2XzNVQZIDnUVKiaG3OYl+p+2acAOpI7z2ZKw7raZFqXqXJ08em8qZ voepAnpIw9HKgY9uywuMeL0bKyd2qJMEtVeX6yKsuUeYfQ836LnknoBVkQIurRBlreTR yRJMKVcytieh/saYNCVMuSBbRdqNcBF1S56jfGv2nlX2EXOZFypieF4kYKxB2Cnzk50K hoD7Z6xyxAs+zzBBOiKy7K8cEkWAKFj4m4MuDsIR9kSeY88bGCNKyDAeqyT76ITQYuIl ambQ== X-Gm-Message-State: AOAM530C3lGo3UkkaqasY9rR4NEphIGENWH8REmj9V9XqEzOBQsrKujv KGOWxiwgOmQiKMdOewYLJVY+Vw/y2taj/g== X-Google-Smtp-Source: ABdhPJx9cWYB2YsySBwGbMpFDrucnYDiY6jYr3wvPHZQ1PCNopVS9YkSMm+NGX+rBLIVW7JzGJfIZg== X-Received: by 2002:a92:dc87:: with SMTP id c7mr21088587iln.279.1614745225715; Tue, 02 Mar 2021 20:20:25 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id q6sm5880881ilm.66.2021.03.02.20.20.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Mar 2021 20:20:25 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id DEB4A8007E9; Tue, 2 Mar 2021 22:20:23 -0600 (CST) Date: Tue, 2 Mar 2021 22:20:23 -0600 From: Justin Pryzby To: Nagaraj Raj Cc: pgsql-performance@lists.postgresql.org Subject: Re: tables meta data collection Message-ID: <20210303042023.GF29832@telsasoft.com> References: <591365510.2330079.1614734451782.ref@mail.yahoo.com> <591365510.2330079.1614734451782@mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <591365510.2330079.1614734451782@mail.yahoo.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Mar 03, 2021 at 01:20:51AM +0000, Nagaraj Raj wrote: > I was trying to collect table metadata with a description; the use case i= s that I need to show all columns of the tables whether it has the descript= ion or not.=A0 > I tried the below query, but it only gives column details that have a des= cription and ignore others if not.=A0 Looks like you should join information_schema.columns *before* pg_catalog.pg_description, otherwise the columns view has nothing to join to unless the column has a description. =2E..or you could use FULL OUTER JOIN on the columns view. > =A0SELECT c.table_schema,c.table_name,c.column_name,case=A0=A0 =A0 when c= =2Edomain_name is not null then c.domain_name=A0 =A0 when c.data_type=3D'ch= aracter varying' THEN 'character varying('||c.character_maximum_length||')'= =A0 =A0 when c.data_type=3D'character' THEN 'character('||c.character_maxim= um_length||')' =A0 =A0 when c.data_type=3D'numeric' THEN 'numeric('||c.nume= ric_precision||','||c.numeric_scale||')'=A0 =A0 else c.data_typeend as data= _type,c.is_nullable,=A0(select 'Y' from information_schema.table_constraint= s tcojoin information_schema.key_column_usage kcu=A0=A0 =A0 =A0on kcu.const= raint_name =3D tco.constraint_name=A0 =A0 =A0and kcu.constraint_schema =3D = tco.constraint_schema=A0 =A0 =A0and kcu.constraint_schema =3D c.table_schem= a=A0and kcu.table_name =3D c.table_name=A0and kcu.column_name =3D c.column_= namewhere tco.constraint_type =3D 'PRIMARY KEY' ) as is_in_PK,(select disti= nct 'Y' from information_schema.table_constraints tcojoin information_schem= a.key_column_usage kcu=A0=A0 =A0 =A0on kcu.constraint_name =3D tco.constrai= nt_name=A0 =A0 =A0and kcu.constraint_schema =3D tco.constraint_schema=A0 = =A0 =A0and kcu.constraint_schema =3D c.table_schema=A0and kcu.table_name = =3D c.table_name=A0and kcu.column_name =3D c.column_namewhere tco.constrain= t_type =3D 'FOREIGN KEY' ) as is_in_FK,pgd.description >=20 > FROM pg_catalog.pg_statio_all_tables as st=A0 Left outer join pg_catalog.= pg_description pgd on (pgd.objoid=3Dst.relid)=A0 left outer join informatio= n_schema.columns c on (pgd.objsubid=3Dc.ordinal_position=A0 =A0 and=A0 c.ta= ble_schema=3Dst.schemaname and c.table_name=3Dst.relname)where c.table_name= =3D'test'order by c.table_schema,c.table_name,c.ordinal_position;=A0 >=20 > expected formate is : >=20 > | table_schema | table_name | column_name | data_type | is_nullable | is_= in_pk | is_in_fk | description | --=20 Justin Pryzby System Administrator Telsasoft +1-952-707-8581