From: | Alban Hertroys <haramrae(at)gmail(dot)com> |
---|---|
To: | John Smith <jayzee(dot)smith(at)gmail(dot)com> |
Cc: | PostgreSQL General <pgsql-general(at)postgresql(dot)org>, PostgreSQL Magazine <contact(at)pgmag(dot)org>, solarsail(at)gmail(dot)com |
Subject: | Re: dynamic table names |
Date: | 2013-07-18 06:55:25 |
Message-ID: | 3B0D7BBA-B08A-4019-8CEB-8287E89ECDB9@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Jul 17, 2013, at 22:39, John Smith <jayzee(dot)smith(at)gmail(dot)com> wrote:
> so my query goes like so:
>
> > execute 'select * from ' || tabname::regclass || ' where firstname = "john"' into e;
Are those quotes around 'john' double-quotes (for identifiers) or double single-quotes (for literals)?
They look like double-quotes to me, so unless your table has a column named "john" (and lowercase at that) that would fail. It's probably not what you meant anyway.
Does this fare any better?
execute 'select * from ' || tabname::regclass || ' where firstname = ''john''' into e;
> but i am getting an error:
>
> > ERROR: syntax error at or near "'select * from '" at character 9
Do you always get that error or do you only get it with certain table names? If so, which ones?
Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.
From | Date | Subject | |
---|---|---|---|
Next Message | Thomas Strunz | 2013-07-18 08:25:39 | Set cost for a specific index scan |
Previous Message | guxiaobo1982 | 2013-07-18 06:34:32 | Reply: Reply: [GENERAL] 回复: [GENERAL] Can't create plpython language |