Re: casting behavior of oids and relation names

From: Vibhor Kumar <vibhor(dot)kumar(at)enterprisedb(dot)com>
To: salah jubeh <s_jubeh(at)yahoo(dot)com>
Cc: pgsql <pgsql-general(at)postgresql(dot)org>
Subject: Re: casting behavior of oids and relation names
Date: 2012-05-16 14:08:02
Message-ID: 0D011A01-64D9-4570-819A-320E8BF32C3A@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On May 16, 2012, at 9:20 AM, salah jubeh wrote:

>
> In some cases when I cast the oid to relation names ('xxxx'::regclass::text) I get schemaname.tablename and in some cases I just get tablename. I thought at the beginning, this is due name duplication of tables in different schemas but it seems not. Also, this seems as a schema option because it happen only in certain schemas. How I can get a consistent names of the casting ?
>

If tablename exists in search_path then it will not show the schemaname. Its normal behavior.
You can create function something like given below for consistent names and can use it:
CREATE OR REPLACE FUNCTION pg_get_relname(oid) RETURNS text
as
$$
SELECT n.nspname||'.'|| c.relname as "Name" FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind='r' and c.oid=$1
$$ language sql;

Thanks & Regards,
Vibhor Kumar
EnterpriseDB Corporation
The Enterprise PostgreSQL Company
Blog: http://vibhork.blogspot.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2012-05-16 14:14:06 Re: maybe incorrect regexp_replace behavior in v8.3.4 ?
Previous Message Gauthier, Dave 2012-05-16 13:54:23 maybe incorrect regexp_replace behavior in v8.3.4 ?