Re: Exposed function to find table in schema search list? - Mailing list pgsql-hackers

From Joe Conway
Subject Re: Exposed function to find table in schema search list?
Date
Msg-id 3CE8183C.9010209@joeconway.com
Whole thread Raw
In response to Exposed function to find table in schema search list?  ("Joel Burton" <joel@joelburton.com>)
Responses Re: Exposed function to find table in schema search list?  ("Joel Burton" <joel@joelburton.com>)
List pgsql-hackers
Joel Burton wrote:
> Is there a function already in the backend to return a class oid, given a
> name, by looking up the table in the current_schemas path? Would it make
> sense for us to expose this, or write one, so that this small wheel doesn't
> have to be re-invented everytime someone wants to find a table by just the
> name?
> 
> Something like:
> 
>   findtable(text) returns oid
>     findtable("foo") -> oid of foo (given current search path)
>     findtable("s.foo") -> oid of s.foo
> 
> I can write something in plpgsql (iterating over the array, checking each,
> etc.), however, it would be nice if something was already there.

I think this already exists:

test=# select 'joe.foo'::regclass::oid;  oid
-------- 125532
(1 row)

test=# select 'public.foo'::regclass::oid;  oid
-------- 125475
(1 row)

test=# select 'foo'::regclass::oid;  oid
-------- 125475
(1 row)

test=# select current_schema(); current_schema
---------------- public
(1 row)

Joe



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [PATCHES] SRF patch (was Re: troubleshooting pointers)
Next
From: "Joel Burton"
Date:
Subject: Re: Exposed function to find table in schema search list?