Automatic creation of SCHEMA in postgresql

0

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

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

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

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

    
asked by anonymous 18.07.2016 / 14:23

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 it;

    
18.07.2016 / 15:51