Thread: How to check is the table system

How to check is the table system

From
Андрей
Date:
Hello!

    In what way can I determine is the table system? ODBC driver does it
by checking table name's prefix: if it begins with 'pg_' - driver
desides that the table is system, but that's a bad idea. I can create
table and call it 'pg_mytable', but it won't become system!

    Big Thanks,
        Andrei


Re: How to check is the table system

From
Alvaro Herrera
Date:
On Thu, Sep 15, 2005 at 09:12:44PM +0300, ???????????? wrote:

>    In what way can I determine is the table system? ODBC driver does it
> by checking table name's prefix: if it begins with 'pg_' - driver
> desides that the table is system, but that's a bad idea. I can create
> table and call it 'pg_mytable', but it won't become system!

If a table is in the pg_catalog schema, it's a system table.  The pg_
prefix was used as a convention before the introduction of schemas in
7.3 -- users were not supposed to create tables with names beggining
with pg_.  I guess it's still a bad idea to create tables with such
names.

--
Alvaro Herrera -- Valdivia, Chile         Architect, www.EnterpriseDB.com
"La gente vulgar solo piensa en pasar el tiempo;
el que tiene talento, en aprovecharlo"

Re: How to check is the table system

From
Tom Lane
Date:
=?UTF-8?B?0JDQvdC00YDQtdC5?= <andyk@softwarium.net> writes:
>     In what way can I determine is the table system? ODBC driver does it
> by checking table name's prefix: if it begins with 'pg_' - driver
> desides that the table is system, but that's a bad idea.

Yup, that's been incorrect since PG 7.3.  The proper test is whether the
table is in the pg_catalog schema.

Depending on your purposes you might also want to exclude pg_toast.

            regards, tom lane

Re: How to check is the table system

From
Martijn van Oosterhout
Date:
On Thu, Sep 15, 2005 at 09:12:44PM +0300, ???????????? wrote:
> Hello!
>
>    In what way can I determine is the table system? ODBC driver does it
> by checking table name's prefix: if it begins with 'pg_' - driver
> desides that the table is system, but that's a bad idea. I can create
> table and call it 'pg_mytable', but it won't become system!

Check it is in the pg_catalog schema...

--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

Re: How to check is the table system

From
"Jim C. Nasby"
Date:
On Thu, Sep 15, 2005 at 09:12:44PM +0300, ???????????? wrote:
> Hello!
>
>    In what way can I determine is the table system? ODBC driver does it
> by checking table name's prefix: if it begins with 'pg_' - driver
> desides that the table is system, but that's a bad idea. I can create
> table and call it 'pg_mytable', but it won't become system!

From http://lnk.nu/cvs.pgfoundry.org/3yb.sql:
-- Note that generic case would be "select $1 like ''pg!_%'' escape ''!''
create or replace function _pg_sv_system_schema(name) returns boolean
  as 'select $1 in (name ''pg_catalog'', name ''pg_toast'',
                    name ''pg_sysviews'', name ''information_schema'')'
  language sql immutable strict;

create or replace function _pg_sv_temp_schema(name) returns boolean
  as 'select $1 like ''pg!_temp!_%'' escape ''!'' '
  language sql immutable strict;

Of course, as others have mentioned, that won't work if you're pre-schemas.
--
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461