Re: pad column with leading zeros or space - Mailing list pgsql-general

From Stephan Szabo
Subject Re: pad column with leading zeros or space
Date
Msg-id 20020123094421.L19046-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Re: pad column with leading zeros or space  ("Johnson, Shaunn" <SJohnson6@bcbsm.com>)
List 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 by date:

Previous
From: Tom Lane
Date:
Subject: Re: persistent portals/cursors (between transactions)
Next
From: "Tom Pfau"
Date:
Subject: Re: pad column with leading zeros or space