Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hcZwr-0001JG-Rj for pgsql-general@arkaria.postgresql.org; Sun, 16 Jun 2019 18:32:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hcZwq-00011n-H1 for pgsql-general@arkaria.postgresql.org; Sun, 16 Jun 2019 18:32:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hcZwq-000116-6j for pgsql-general@lists.postgresql.org; Sun, 16 Jun 2019 18:32:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hcZwn-0004sw-K5 for pgsql-general@lists.postgresql.org; Sun, 16 Jun 2019 18:32:11 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x5GIW0r4020114; Sun, 16 Jun 2019 14:32:00 -0400 From: Tom Lane To: "Peter J. Holzer" cc: pgsql-general@lists.postgresql.org Subject: Re: bug regclass::oid In-reply-to: <20190616181250.x6l3n7bq2j5z4onq@hjp.at> References: <20190616181250.x6l3n7bq2j5z4onq@hjp.at> Comments: In-reply-to "Peter J. Holzer" message dated "Sun, 16 Jun 2019 20:12:50 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <20112.1560709920.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 16 Jun 2019 14:32:00 -0400 Message-ID: <20113.1560709920@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "Peter J. Holzer" writes: > On 2019-06-16 18:03:02 +0200, John Mikel wrote: >> here is my query=C2=A0 >> =C2=A0select=C2=A0 =C2=A0A.table_name=C2=A0 as "table_name",A.domain_na= me as "domain", >> =C2=A0format_type(c.atttypid, c.atttypmod)=C2=A0 AS data_type ,A.column= _name as >> "column_name", >> =C2=A0 A.is_nullable as "nullable",A.column_default as "default" >> =C2=A0 from information_schema.columns A inner=C2=A0 join pg_attribute = c=C2=A0 on=C2=A0 >> a.table_name::regclass::oid=3Dc.attrelid >> =C2=A0 where=C2=A0 a.table_schema in (select current_schema()) and=C2=A0= a.column_name =3D >> c.attname=C2=A0; >> = >> if i run this query in any database contain at least one table with spa= ce in >> their name , an error occurred > You have to quote the table name [ with quote_ident ] Note that that's still unreliable, because it's not considering the possibility of duplicate table names in different schemas. You could do something like where (quote_ident(a.table_schema) || '.' || quote_ident(a.table_name))::regcl= ass =3D c.attrelid If that seems awfully brute-force, you're right, but I think it's self-inflicted damage from trying to mix two different levels of abstraction -- namely, the information_schema and the underlying native PG catalogs. I'd suggest recasting this as a join between pg_catalog and pg_attribute, which would make the join condition just "where c.oid =3D a.attrelid". regards, tom lane