Re: problem with variable - Mailing list pgsql-novice

From Michael Wood
Subject Re: problem with variable
Date
Msg-id AANLkTimKm2EO9D42jPzL8SAlEG-j03Dx6xK0eKOyZUF5@mail.gmail.com
Whole thread Raw
In response to Re: problem with variable  ("coviolo@libero.it" <coviolo@libero.it>)
Responses Re: problem with variable
List pgsql-novice
Hi

On 9 June 2010 16:24, coviolo@libero.it <coviolo@libero.it> wrote:
> something like this:
>
> IF (TG_OP = 'UPDATE') THEN
> EXECUTE 'CREATE TABLE '||NEW.nome_tabella||' (ordinativo serial PRIMARY KEY
> CHECK (nome_tabella = '''||NEW.nome_tabella||'''::text))
> INHERITS (database_t);
>
> 3 quotes first and 3 quotes after the second variable?

Just a guess, but I think this is what you want:

IF (TG_OP = 'UPDATE') THEN
EXECUTE 'CREATE TABLE ' || NEW.nome_tabella || ' (ordinativo serial PRIMARY KEY
CHECK (nome_tabella = "' || NEW.nome_tabella || '"::text))
INHERITS (database_t);'

i.e. you want:

CREATE TABLE table_name (x serial PRIMARY KEY
CHECK (column_name = "table_name"::text))
INHERITS (database_t);

The first "table_name" is not quoted.  The second one has
double-quotes (") around it.  So you need the whole thing to be quoted
with single-quotes (') and then use '...' || variable || '...' for the
first one and '..."' || variable || '"::text...' for the second one.

I hope that makes sense.

--
Michael Wood <esiotrot@gmail.com>

pgsql-novice by date:

Previous
From: "coviolo@libero.it"
Date:
Subject: Re: problem with variable
Next
From: Michael Wood
Date:
Subject: Re: problem with variable