how to search for relation by name?

Lists: pgsql-general
From: zach cruise <zachc1980(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: how to search for relation by name?
Date: 2009-04-22 21:36:25
Message-ID: bcdac0e80904221436n37f82da0raabc65d6a03c7d1d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

when i try to copy database (into another database), i get "relation
does not exist" errors for 'super objects' like sequences. (that is
fine since i am using pg_dump, not pg_dumpall) but there is one
relation i can't find to recreate in the new database.

how can i search database for relation by name (some catalog table)?


From: DM <dm(dot)aeqa(at)gmail(dot)com>
To: zach cruise <zachc1980(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: how to search for relation by name?
Date: 2009-04-22 22:14:29
Message-ID: eae6a62a0904221514m10513b07jf5e9b7047447e2a7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Here is the sql

SELECT c.oid,
n.nspname,
c.relname
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname LIKE ('%dt%')
AND pg_catalog.pg_table_is_visible(c.oid)

replace dt with your sequence name

pg_catalog has the information.

Thanks
Deepak

On Wed, Apr 22, 2009 at 2:36 PM, zach cruise <zachc1980(at)gmail(dot)com> wrote:

> when i try to copy database (into another database), i get "relation
> does not exist" errors for 'super objects' like sequences. (that is
> fine since i am using pg_dump, not pg_dumpall) but there is one
> relation i can't find to recreate in the new database.
>
> how can i search database for relation by name (some catalog table)?
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>


From: zach cruise <zachc1980(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: DM <dm(dot)aeqa(at)gmail(dot)com>
Subject: Re: how to search for relation by name?
Date: 2009-04-23 17:21:45
Message-ID: bcdac0e80904231021l18c7626pbbe4e8dbf5a39704@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Thanks! I just created new database using old database as template,
and everything got copied over without errors. is that recommended
over pg_dump though when just recreating database for different
encoding?

http://www.postgresql.org/docs/8.1/interactive/manage-ag-templatedbs.html

On Wed, Apr 22, 2009 at 6:14 PM, DM <dm(dot)aeqa(at)gmail(dot)com> wrote:
> Here is the sql
> SELECT c.oid,
>   n.nspname,
>   c.relname
> FROM pg_catalog.pg_class c
>      LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
> WHERE c.relname LIKE ('%dt%')
>   AND pg_catalog.pg_table_is_visible(c.oid)
> replace dt with your sequence name
> pg_catalog has the information.
> Thanks
> Deepak
>
> On Wed, Apr 22, 2009 at 2:36 PM, zach cruise <zachc1980(at)gmail(dot)com> wrote:
>>
>> when i try to copy database (into another database), i get "relation
>> does not exist" errors for 'super objects' like sequences. (that is
>> fine since i am using pg_dump, not pg_dumpall) but there is one
>> relation i can't find to recreate in the new database.
>>
>> how can i search database for relation by name (some catalog table)?
>>
>> --
>> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-general


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: zach cruise <zachc1980(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, DM <dm(dot)aeqa(at)gmail(dot)com>
Subject: Re: how to search for relation by name?
Date: 2009-04-23 17:34:06
Message-ID: 528.1240508046@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

zach cruise <zachc1980(at)gmail(dot)com> writes:
> Thanks! I just created new database using old database as template,
> and everything got copied over without errors. is that recommended
> over pg_dump though when just recreating database for different
> encoding?

It's pretty much guaranteed not to work, since the data will just be
copied without any encoding conversion. You could possibly get away
with it if the database is empty of data.

regards, tom lane