From: | "Jasbinder Singh Bali" <jsbali(at)gmail(dot)com> |
---|---|
To: | "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "Peter Schonefeld" <peter(dot)schonefeld(at)gmail(dot)com>, pgsql-novice(at)postgresql(dot)org |
Subject: | Re: help with dynamic table name |
Date: | 2007-03-06 04:49:50 |
Message-ID: | a47902760703052049g559f6a22k1dd70d89aac7e072@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
thats wot i suggested him in my last email :)
~Jas
On 3/5/07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> "Jasbinder Singh Bali" <jsbali(at)gmail(dot)com> writes:
> > On 3/5/07, Peter Schonefeld <peter(dot)schonefeld(at)gmail(dot)com> wrote:
> >> sql := "INSERT INTO "+ $3 +" ('id','body') VALUES ("+ $1 +","+ $2 +")";
> >>
> >> I get the error: "ERROR: 42703: column \"INSERT INTO \" does not exist"
>
> > try replacing double quotes with single quotes and you should be fine i
> > think
>
> Actually, I think Peter's got the double and single quotes exactly
> backwards. You can't just randomly use one or the other: single quotes
> surround literal strings, double quotes surround identifiers (and are
> only really needed if the identifier wouldn't be syntactically an
> identifier without them). So Peter could write
>
> sql := 'INSERT INTO '+ $3 +' ("id","body") VALUES ('+ $1 +','+ $2 +')';
>
> but in this particular case there's no point in double-quoting those
> target-column names; it'd be the same to write
>
> sql := 'INSERT INTO '+ $3 +' (id,body) VALUES ('+ $1 +','+ $2 +')';
>
> regards, tom lane
>
From | Date | Subject | |
---|---|---|---|
Next Message | Stephan Szabo | 2007-03-06 05:00:04 | Re: help with dynamic table name |
Previous Message | Tom Lane | 2007-03-06 04:48:49 | Re: help with dynamic table name |