Re: pad column with leading zeros or space

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: pad column with leading zeros or space
Дата
Msg-id 20020123094421.L19046-100000@megazone23.bigpanda.com
обсуждение исходный текст
Ответ на Re: pad column with leading zeros or space  ("Johnson, Shaunn" <SJohnson6@bcbsm.com>)
Список pgsql-general
On Wed, 23 Jan 2002, Johnson, Shaunn wrote:

In general, Tom's right that it's probably best to do this in the front
end, but...

> create table foo (
> member_id lpad(10, '0')
> );
>
> [/snip guess]
>
> I know this doesn't work, but that's sorta what I'm going for.

If you want it to really be stored with all the 0's, a trigger
would probably do what you want. If you want it converted
to the text string with 0's when a select is done, you'd probably
want a view to do the manipulation for you.

(trigger example - mostly untested:)
create table foo (
 member_id text
);

create function foofunc() returns opaque as
'begin
  NEW.member_id := lpad(NEW.member_id, 10, ''0'');
  return NEW;
 end;'
language 'plpgsql';

create trigger t1 before insert or update on foo
 for each row execute procedure foofunc();


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: persistent portals/cursors (between transactions)
Следующее
От: "Tom Pfau"
Дата:
Сообщение: Re: pad column with leading zeros or space