Thread: How do you query all columns and all tables for a specific string

How do you query all columns and all tables for a specific string

From
Ryan Garvey
Date:
I recently inhereted a database that I know nothing about that has hundreds of tables most of which have meaningless names, or at least to me. I am trying to find a table and column that holds a specific serial number. I have no idea what table or what column it would be stored in. Is it possible to search the entire database?

Re: How do you query all columns and all tables for a specific string

From
"A. Kretschmer"
Date:
In response to Ryan Garvey :
> I recently inhereted a database that I know nothing about that has hundreds of
> tables most of which have meaningless names, or at least to me. I am trying to
> find a table and column that holds a specific serial number. I have no idea
> what table or what column it would be stored in. Is it possible to search the
> entire database?

That's not the usual way to deal with a database, but you can create a
database-dump and use tools like grep to find your number in the dump. I
think, this is the fastest way. If you have found your number you can
read the dump to obtain, which table/column holds this value.


Regards, Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431  2EB0 389D 1DC2 3172 0C99

Re: How do you query all columns and all tables for a specific string

From
Jasen Betts
Date:
On 2010-03-22, Ryan Garvey <ryan.garvey1@gmail.com> wrote:
> --001517448026efc884048265d16b
> Content-Type: text/plain; charset=ISO-8859-1
>
> I recently inhereted a database that I know nothing about that has hundreds
> of tables most of which have meaningless names, or at least to me. I am
> trying to find a table and column that holds a specific serial number. I
> have no idea what table or what column it would be stored in. Is it possible
> to search the entire database?

you could scan a dump of the for the serial number you want and work
back from there.


eg: assuming the serial you want is '1234237854'

  pg_dump databasename | egrep  '^COPY|1234237854' | grep -B1 '1234237854'