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

Re: help with dynamic table name

From: "Jasbinder Singh Bali" <jsbali(at)gmail(dot)com>
To: "Peter Schonefeld" <peter(dot)schonefeld(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: help with dynamic table name
Date: 2007-03-06 04:48:44
Message-ID: a47902760703052048w5cd35326g95f84d41ea2023c7@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
sql := 'INSERT INTO '+ $3 +' (id,body) VALUES ('+ $1 +','+ $2 +')';
remove the double quotes with id and body and see if it works.
~Jas



On 3/5/07, Peter Schonefeld <peter(dot)schonefeld(at)gmail(dot)com> wrote:
>
> Hi Jas, thanks for the quick reply...I had started out with the single
> quotes, but had chaged it in my many efforts to get the thing to work...with
> the single quotes i'm getting the error:
>
> "ERROR: 42883: operator does not exist: \"unknown\" + character varying"
>
> ====
>
> CREATE OR REPLACE FUNCTION sc_insert_row(char(32),text ,varchar(32))
> RETURNS text AS $$
>
> DECLARE sql text;
> BEGIN
>   sql := 'INSERT INTO '+ $3 +' ("id","body") VALUES ('+ $1 +','+ $2 +')';
>   EXECUTE sql;
>   RETURN '';
> END;
>
> $$ LANGUAGE 'plpgsql' VOLATILE;
>
>
> Pete
>
>
>
> On 3/6/07, Jasbinder Singh Bali <jsbali(at)gmail(dot)com> wrote:
> >
> > try replacing double quotes with single quotes and you should be fine i
> > think
> > ~Jas
> >
> >
> >  On 3/5/07, Peter Schonefeld <peter(dot)schonefeld(at)gmail(dot)com > wrote:
> > >
> > > Hi, could someone please let me know what i'm doing wrong here?
> > >
> > > CREATE OR REPLACE FUNCTION sc_insert_row(char(32),text,varchar(32))
> > > RETURNS text AS $$
> > >
> > > DECLARE sql text;
> > > BEGIN
> > >   sql := "INSERT INTO "+ $3 +" ('id','body') VALUES ("+ $1 +","+ $2
> > > +")";
> > >   EXECUTE sql;
> > >   RETURN '';
> > > END;
> > >
> > > $$ LANGUAGE 'plpgsql' VOLATILE;
> > >
> > > I get the error: "ERROR: 42703: column \"INSERT INTO \" does not
> > > exist"
> > >
> > > Cheers
> > > Pete
> > >
> >
> >
>

In response to

pgsql-novice by date

Next:From: Tom LaneDate: 2007-03-06 04:48:49
Subject: Re: help with dynamic table name
Previous:From: Jasbinder Singh BaliDate: 2007-03-06 04:42:17
Subject: Re: help with dynamic table name

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