problem with variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sentenza
    New Member
    • May 2010
    • 7

    problem with variable

    Hello everyone

    When the trigger executes the function which I copy below:

    Code:
    IF (TG_OP = 'UPDATE') THEN
    EXECUTE 'CREATE TABLE '||NEW.nome_tabella||' (ordinativo serial PRIMARY KEY
    CHECK (nome_tabella = '||NEW.nome_tabella||'::text))
    INHERITS (madre);
    first use of the variable '||NEW.nome_tab ella||' is correct and the table is created with the name, for example "azienda_vallon e", but I do not know why, the second use of the variable is incorrect because the CHECK insert on table is nome_tabella = azienda_vallone .*.
    I can not understand why postgresql insert point and asterisk at the end of the variable.
    if anyone can give me some suggestions on how to resolve...

    thank you very much
    Luca
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    Originally posted by sentenza
    Hello everyone

    When the trigger executes the function which I copy below:

    Code:
    IF (TG_OP = 'UPDATE') THEN
    EXECUTE 'CREATE TABLE '||NEW.nome_tabella||' (ordinativo serial PRIMARY KEY
    CHECK (nome_tabella = '||NEW.nome_tabella||'::text))
    INHERITS (madre);
    first use of the variable '||NEW.nome_tab ella||' is correct and the table is created with the name, for example "azienda_vallon e", but I do not know why, the second use of the variable is incorrect because the CHECK insert on table is nome_tabella = azienda_vallone .*.
    I can not understand why postgresql insert point and asterisk at the end of the variable.
    if anyone can give me some suggestions on how to resolve...

    thank you very much
    Luca
    NEW is not a variable but a 'table' (virtual one).
    I guess that 'madre' table contains column nome_tabella, does it?
    Maybe you should first copy value NEW.nome_tabell a to some variable (using := operator) and then use the variable into check statement.

    Comment

    Working...