Re: function likes sprintf

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: function likes sprintf
Дата
Msg-id 008c01c09819$77ff5380$1001a8c0@archonet.com
обсуждение исходный текст
Ответ на function likes sprintf  ("Mikhail V. Majorov" <mik@ttn.ru>)
Список pgsql-general
From: "Mikhail V. Majorov" <mik@ttn.ru>


> Hi all!
>
> Do pgsql function like sprintf() in C?
> I write trigger function using plpgsql.
>
> This my code:
> sqlcommand := textcat(''CREATE USER '',NEW.usename);
> sqlcommand := textcat(sqlcommand, ''WITH SYSID '');
> sqlcommand := textcat(sqlcommand, NEW.id);
> sqlcommand := textcat(sqlcommand, ''WITH PASSWORD '');
> sqlcommand := textcat(sqlcommand, passwd);
> INSERT INTO todo_surep_user VALUES (sqlcommand, now(), '''');
>
> How do I replace "textcat" on another construct of language?

You can use the || operator such as:

sqlcommand := "CREATE USER " || NEW.usename || "WITH SYSID" ...

If you are after the more advanced formatting %7.3f stuff you'll need to
look at the various procedural languages (pltcl,plperl) - you could write
you own function to emulate sprintf but I don't think the interface supports
a variable number of parameters.

- Richard Huxton


В списке pgsql-general по дате отправления:

Предыдущее
От: Mike Mascari
Дата:
Сообщение: Triggers and RI-style behavior.
Следующее
От: "Richard Huxton"
Дата:
Сообщение: Re: [araman@india-today.com: locking problem with JDBC (suspicion)]