0

Hi My question is already asked here

But i haven't found any answer there in that link. I don't want any tool to acheive my requirement. I am looking for a simple procedure or query. In that link someone answered about search_columns() procedure. Right now i am using postgresql 9.0.4 version. Can some Postgresql Guru over there can answer this problem

Also Is there any alternative for format() function for 9.1 below versions. I see that the format() function is supported in postresql 9.1 versions and above. Can anybody tell me how to use format function or any alternative to format function for 9.0 or below versions.

Thanks in advance

Community
  • 1
  • 1
soft4time
  • 1
  • 4

1 Answers1

1

On old versions you must instead use quote_ident and quote_literal with concatenation operations.

e.g.

format('SELECT %I FROM %I WHERE %I = %L', col1, tbl, col2, val)

becomes

'SELECT '||quote_ident(col1)||' FROM '||quote_ident(tbl)||' WHERE '||quote_ident(col2)||' = '||quote_nullable(val);
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • 1
    Almost perfect, but `%L` should be replaced by `quote_nullable()` http://www.postgresql.org/docs/current/static/functions-string.html#FUNCTIONS-STRING-FORMAT – pozs Nov 20 '14 at 09:07