pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: solarsail <solarsail@gmail.com>
To: pgsql-sql@postgresql.org
Subject: using pg_tables and tablename in queries
Date: Tue, 4 Oct 2005 12:30:55 -0400
Message-ID: <aa44f4a30510040930m510bbe8do4babd97b1b37c90d@mail.gmail.com> (raw)

I have a large number of tables with a common naming convention

mytable001, mytable002, mytable003 ... mytable00n

I would like to do a query across all of the tables, however I do not know
all of the tables before hand, and I do not want to ( cant ) manually
generate a query like

select * from mytable001, mytable002, mytable003


I have a query that returns the names of the tables I want to query:

select tablename from pg_tables where tablename like 'mytable%'


I have successfully done this query before. I remember it used a odd syntax;
I it was something like

select * from ( select tablename from pg_tables where tablename like
'mytable%' )


However the above query returns just a listing of tables, I need to use its
output in the FROM and treat the input as a table name.

( I've tried creating a Table Function that returns the above set and tried
to use that in a select clause, but I cant get it to work. )

view thread (10+ messages)  latest in thread

Message-ID: <aa44f4a30510040930m510bbe8do4babd97b1b37c90d@mail.gmail.com>
Permalink:  ../aa44f4a30510040930m510bbe8do4babd97b1b37c90d@mail.gmail.com/
Also on:    postgresql.org/message-id/aa44f4a30510040930m510bbe8do4babd97b1b37c90d@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: solarsail@gmail.com
  Subject: Re: using pg_tables and tablename in queries
  In-Reply-To: <aa44f4a30510040930m510bbe8do4babd97b1b37c90d@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox