Automatic SCHEMA creation in postgresql

Asked

Viewed 78 times

0

I’m having a problem with the following, I need to create a Rigger that when a given row is inserted it creates a SCHEMA with a specific structure! For example, in the public scheme, I have the client table, and when I insert some client, I need to create a Trigger with the client’s name.

INSERT INTO public.cliente (idcliente, nome) VALUES (2,'joao');

In that case, he would automatically create a SCHEMA with the name of John, but I have no idea how to do that.

I need to create a function that takes the SCHEMA name as parameter and within this function create the SCHEMA?

  • 1

    What a strange thing, huh? This looks like something very wrong.

  • What is the purpose of creating a new schema for each record?

  • In fact, is that each user of a given system will have its own SCHEMA, it was not I who created this rule and if it were for me I would not do so too.

1 answer

0

The fastest way is to make a script with some desired language.

Example in PHP:

// faz a conexão normal;

$VariavelQueRecebeNome = 'joao';

// executa o insert normalmente;

$sCriarSchema = "CREATE SCHEMA ".$VariavelQueRecebeNome."; ";

$rsQuery = pg_query($sCriarSchema);

There are "n" ways to do;

  • I thought about it exactly, but I was asked to make a Rigger, which also helps me to learn a little more about triggers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.