Skip site navigation (1) Skip section navigation (2)

Re: problem with variable

From: Michael Wood <esiotrot(at)gmail(dot)com>
To: "coviolo(at)libero(dot)it" <coviolo(at)libero(dot)it>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: problem with variable
Date: 2010-06-09 14:51:18
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice

On 9 June 2010 16:24, coviolo(at)libero(dot)it <coviolo(at)libero(dot)it> wrote:
> something like this:
> 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:

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(at)gmail(dot)com>

In response to


pgsql-novice by date

Next:From: Michael WoodDate: 2010-06-09 14:54:44
Subject: Re: problem with variable
Previous:From: coviolo@libero.itDate: 2010-06-09 14:24:36
Subject: Re: problem with variable

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group