Unix Technical Forum

How to check is the table system

This is a discussion on How to check is the table system within the Pgsql General forums, part of the PostgreSQL category; --> Hello! In what way can I determine is the table system? ODBC driver does it by checking table name's ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 05:58 AM
=?UTF-8?B?0JDQvdC00YDQtdC5?=
 
Posts: n/a
Default How to check is the table system

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


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 05:58 AM
Alvaro Herrera
 
Posts: n/a
Default Re: How to check is the table system

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"

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 05:58 AM
Tom Lane
 
Posts: n/a
Default Re: How to check is the table system

=?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

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-09-2008, 05:58 AM
Martijn van Oosterhout
 
Posts: n/a
Default Re: How to check is the table system

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.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFDKb/6IB7bNG8LQkwRAn74AJ9qB99EnFcx+bwT+jCJzNelQk4QpQCgh mw2
pbrAo2kT38JyGK00Ae3G1Qg=
=iiOI
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-09-2008, 06:00 AM
Jim C. Nasby
 
Posts: n/a
Default Re: How to check is the table system

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

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:44 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com