format() function with string_agg

From: Raj Gandhi <raj01gandhi(at)gmail(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: format() function with string_agg
Date: 2014-09-24 02:17:08
Message-ID: CALU_HCOEBFAibCcCSBGKdGL7+Shd5vSZLGVBe6XqmM77SanUJA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

I'm trying to use format() function with string_agg with Postgres 9.1.9 but
getting error - "too few arguments for format"

I have two tables t_message and t_message_args. Table t_message has
'message' column with text in the format 'Test message first arg is %1$s
and second arg %2$s end-of-message'

id | integer |
message | character varying |

And the second table t_message_args contains message argument and values
id | integer |
arg | integer |
argvalue | character varying |

Here is the SQL that uses format() function to retrieve formatted message
by replacing arg value in the message:
=
select m.id, format(m.message, string_agg(a.argvalue, ',' order by a.arg)
from t_message m, t_message_args a
where m.id = a.id
group by m.id, m.message

ERROR: too few arguments for format

********** Error **********

ERROR: too few arguments for format
SQL state: 22023

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message David G Johnston 2014-09-24 03:09:04 Re: format() function with string_agg
Previous Message Jeff Frost 2014-09-23 16:44:39 Re: Clarification on pg_basebackup