Re: CREATE TABLE with a name derived from a string - Mailing list pgsql-general

From John Savage
Subject Re: CREATE TABLE with a name derived from a string
Date
Msg-id 006801c2d45e$36aae920$bafe7343@development1
Whole thread Raw
In response to Re: CREATE TABLE with a name derived from a string  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
List pgsql-general
I came across the EXECUTE command while googling for a solution to this
problem but found
a) it was incredibly hard to read because of all the quotes and
b) I couldn't find much documentation for it. It isn't mentioned on the main
red hat postgreSQL manual pages at all
(http://www.redhat.com/docs/manuals/database/) and the word EXECUTE isn't
the best word to google on :). The best resource for plpgsql I could find is
at http://www.phpfreaks.com/postgresqlmanual/page/plpgsql.html but I wasn't
sure if this was going to help me. Are there any better resources for
plpgsql? I'll look into it more now anyway. Thanks.

Meantime, I got a reply from Dmitry Tkach yesterday that made me reconsider
why we are taking this approach. Short term I no longer need this
functionality, but will be needing it over the coming weeks for definite.

Thanks,
John



  _____

John Savage <mailto:jsavage@data-mate.com>
Software Engineer DataMate Global Communications
Tel: +1 818 487 3900 ext105
  _____



-----Original Message-----
From: Stephan Szabo [mailto:sszabo@megazone23.bigpanda.com]
Sent: Friday, February 14, 2003 10:36 AM
To: Savage
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] CREATE TABLE with a name derived from a string


On 12 Feb 2003, Savage wrote:

> I am creating a DB for a multi user IM system. Each user can store
> their history. Each user also has a unique ID. There will be many
> users and a lot of history will be generated by each user, so we are
> going to create a history table per user, with a tablename that is
> derived from the unique userid. I've hit a problem implementing this
> scheme.
>
> I want to be able to write a stored procedure in postgres that takes
> an integer userid as a param and creates a table called
> History.<userid>. (e.g. History.695). My dream is:
>
> CREATE TABLE 'History' || $1 (...);

I think using execute might work:

EXECUTE ''CREATE TABLE History'' || $1 || '' (...);'';



pgsql-general by date:

Previous
From: "Ben-Nes Michael"
Date:
Subject: instaling pg to new directory when upgrading
Next
From: frag
Date:
Subject: Re: Restore from 7.3 to 7.2