Re: dynamic table names - Mailing list pgsql-general

From Alban Hertroys
Subject Re: dynamic table names
Date
Msg-id 3B0D7BBA-B08A-4019-8CEB-8287E89ECDB9@gmail.com
Whole thread Raw
In response to dynamic table names  (John Smith <jayzee.smith@gmail.com>)
List pgsql-general
On Jul 17, 2013, at 22:39, John Smith <jayzee.smith@gmail.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.



pgsql-general by date:

Previous
From: "guxiaobo1982"
Date:
Subject: =?gb18030?B?UmVwbHk6IFJlcGx5OiBbR0VORVJBTF0gu9i4tKO6?= =?gb18030?B?IFtHRU5FUkFMXSBDYW4ndCBjcmVhdGUgcGxweXRo?= =?gb18030?B?b24gbGFuZ3VhZ2U=?=
Next
From: Arvind Singh
Date:
Subject: new instance of postgres on windows