From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter J. Holzer <hjp-pgsql@hjp.at>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: bug regclass::oid
Date: Sun, 16 Jun 2019 14:32:00 -0400
Message-ID: <20113.1560709920@sss.pgh.pa.us> (raw)
In-Reply-To: <20190616181250.x6l3n7bq2j5z4onq@hjp.at>
References: <CAAC-7YB4HUCZ2pq1FEndxYAzRgy8CcGzU0YGVsNAcDLm6nC6kw@mail.gmail.com>
<fc6a3ada-db64-a6e1-b5d7-4f4b2882eb4c@aklaver.com>
<CAAC-7YBGf-i0e-PACrXRUOJ44RerhZqjdep59b1Vc2BsKrcScA@mail.gmail.com>
<20190616181250.x6l3n7bq2j5z4onq@hjp.at>
"Peter J. Holzer" <hjp-pgsql@hjp.at> writes:
> On 2019-06-16 18:03:02 +0200, John Mikel wrote:
>> here is my query
>> select A.table_name as "table_name",A.domain_name as "domain",
>> format_type(c.atttypid, c.atttypmod) AS data_type ,A.column_name as
>> "column_name",
>> A.is_nullable as "nullable",A.column_default as "default"
>> from information_schema.columns A inner join pg_attribute c on
>> a.table_name::regclass::oid=c.attrelid
>> where a.table_schema in (select current_schema()) and a.column_name =
>> c.attname ;
>>
>> if i run this query in any database contain at least one table with space 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))::regclass = 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 = a.attrelid".
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, hjp-pgsql@hjp.at
Subject: Re: bug regclass::oid
In-Reply-To: <20113.1560709920@sss.pgh.pa.us>
References: <CAAC-7YB4HUCZ2pq1FEndxYAzRgy8CcGzU0YGVsNAcDLm6nC6kw@mail.gmail.com> <fc6a3ada-db64-a6e1-b5d7-4f4b2882eb4c@aklaver.com> <CAAC-7YBGf-i0e-PACrXRUOJ44RerhZqjdep59b1Vc2BsKrcScA@mail.gmail.com> <20190616181250.x6l3n7bq2j5z4onq@hjp.at> <20113.1560709920@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox