Search Postgresql Archives

Re: dynamic table names

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Jul 17, 2013, at 22:39, John Smith <jayzee.smith@xxxxxxxxx> 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.



-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux