CREATE TABLE with a name derived from a string

Поиск
Список
Период
Сортировка
От JSavage@data-mate.com (Savage)
Тема CREATE TABLE with a name derived from a string
Дата
Msg-id c23c6cdc.0302121921.3150f1a3@posting.google.com
обсуждение исходный текст
Ответы Re: CREATE TABLE with a name derived from a string
Re: CREATE TABLE with a name derived from a string
Список pgsql-general
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 (...);

but this won't work. I dabbled with plpgsql but didn't get very far
(I'm not an expert at this stuff :( ). I also tried the ALTER TABLE XX
RENAME TO YY but this won't allow strings for the table names either
:(.

I know that this could be done relatively easily be creating the
queries in C++ and executing them, but I want to do as much as
possible in stored procedures for many reasons (performance, reuse,
abstraction from DB changes...).

Has anyone any experience doing something similar? Any help or
pointers would be appreciated.

Thanks,
John

В списке pgsql-general по дате отправления:

Предыдущее
От: Deepa
Дата:
Сообщение: Hi,
Следующее
От: nandrats@mail.mdanderson.org
Дата:
Сообщение: postgres not accessible in Mandrake 9.0