pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
weird(to me) request
5+ messages / 3 participants
[nested] [flat]

* weird(to me) request
@ 2003-09-25 18:51  Larry Rosenman <ler@lerctr.org>
  0 siblings, 2 replies; 5+ messages in thread

From: Larry Rosenman @ 2003-09-25 18:51 UTC (permalink / raw)
  To: pgsql-sql

I have the following rows (in addition to others):

acct_num text,
master_acct_num text,


These are in the same table.

What I want to enforce is that if the master_acct_num field is NOT NULL (it 
can be NULL, and
that's fine), that the value appears in some row as acct_num.  acct_num has 
a unique index on it, so that's fine.

I'm not sure how to do this....

Thanks!

LER


-- 
Larry Rosenman                     http://www.lerctr.org/~ler
Phone: +1 972-414-9812                 E-Mail: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: weird(to me) request
@ 2003-09-25 18:59  Adam Wieckowski <adam-wieckowski@tlen.pl>
  parent: Larry Rosenman <ler@lerctr.org>
  1 sibling, 1 reply; 5+ messages in thread

From: Adam Wieckowski @ 2003-09-25 18:59 UTC (permalink / raw)
  To: Larry Rosenman <ler@lerctr.org>; +Cc: pgsql-sql

Użytkownik Larry Rosenman napisał:

> I have the following rows (in addition to others):
>
> acct_num text,
> master_acct_num text,
>
>
> These are in the same table.
>
> What I want to enforce is that if the master_acct_num field is NOT 
> NULL (it can be NULL, and
> that's fine), that the value appears in some row as acct_num.  
> acct_num has a unique index on it, so that's fine.
>
> I'm not sure how to do this....
>
> Thanks!
>
> LER
>
>
select
    case
        when master_acct_num is null
            then acct_num
        else master_acct_num
    end
    from table;

did you mained somethink like this ?

Attachments:

  smime.p7s (application/x-pkcs7-signature, 4.0K) download

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: weird(to me) request
@ 2003-09-25 19:02  Larry Rosenman <ler@lerctr.org>
  parent: Adam Wieckowski <adam-wieckowski@tlen.pl>
  0 siblings, 0 replies; 5+ messages in thread

From: Larry Rosenman @ 2003-09-25 19:02 UTC (permalink / raw)
  To: Adam Wieckowski <adam-wieckowski@tlen.pl>; +Cc: pgsql-sql



--On Thursday, September 25, 2003 20:59:25 +0200 Adam Wieckowski 
<adam-wieckowski@tlen.pl> wrote:

> U¿ytkownik Larry Rosenman napisa³:
>
>> I have the following rows (in addition to others):
>>
>> acct_num text,
>> master_acct_num text,
>>
>>
>> These are in the same table.
>>
>> What I want to enforce is that if the master_acct_num field is NOT
>> NULL (it can be NULL, and
>> that's fine), that the value appears in some row as acct_num.
>> acct_num has a unique index on it, so that's fine.
>>
>> I'm not sure how to do this....
>>
>> Thanks!
>>
>> LER
>>
>>
> select
>     case
>         when master_acct_num is null
>             then acct_num
>         else master_acct_num
>     end
>     from table;
>
> did you mained somethink like this ?

I'm actually looking to enforce the fact that if master_acct_num is 
entered, it points
to a valid acct_num.

LER



-- 
Larry Rosenman                     http://www.lerctr.org/~ler
Phone: +1 972-414-9812                 E-Mail: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: weird(to me) request
@ 2003-09-25 19:09  Richard Huxton <dev@archonet.com>
  parent: Larry Rosenman <ler@lerctr.org>
  1 sibling, 1 reply; 5+ messages in thread

From: Richard Huxton @ 2003-09-25 19:09 UTC (permalink / raw)
  To: Larry Rosenman <ler@lerctr.org>; pgsql-sql

On Thursday 25 September 2003 19:51, Larry Rosenman wrote:
> I have the following rows (in addition to others):
>
> acct_num text,
> master_acct_num text,
>
>
> These are in the same table.
>
> What I want to enforce is that if the master_acct_num field is NOT NULL (it
> can be NULL, and
> that's fine), that the value appears in some row as acct_num.  acct_num has
> a unique index on it, so that's fine.
>
> I'm not sure how to do this....

ALTER TABLE my_table ADD CONSTRAINT my_self_fk FOREIGN KEY (master_acct_num) 
REFERENCES my_table (acct_num);

It's really just a foreign-key to yourself
-- 
  Richard Huxton
  Archonet Ltd



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: weird(to me) request
@ 2003-09-25 19:16  Larry Rosenman <ler@lerctr.org>
  parent: Richard Huxton <dev@archonet.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Larry Rosenman @ 2003-09-25 19:16 UTC (permalink / raw)
  To: Richard Huxton <dev@archonet.com>; pgsql-sql



--On Thursday, September 25, 2003 20:09:35 +0100 Richard Huxton 
<dev@archonet.com> wrote:

> On Thursday 25 September 2003 19:51, Larry Rosenman wrote:
>> I have the following rows (in addition to others):
>>
>> acct_num text,
>> master_acct_num text,
>>
>>
>> These are in the same table.
>>
>> What I want to enforce is that if the master_acct_num field is NOT NULL
>> (it can be NULL, and
>> that's fine), that the value appears in some row as acct_num.  acct_num
>> has a unique index on it, so that's fine.
>>
>> I'm not sure how to do this....
>
> ALTER TABLE my_table ADD CONSTRAINT my_self_fk FOREIGN KEY
> (master_acct_num)  REFERENCES my_table (acct_num);
>
> It's really just a foreign-key to yourself
I wasn't sure I could do that.  Thanks!

LER


-- 
Larry Rosenman                     http://www.lerctr.org/~ler
Phone: +1 972-414-9812                 E-Mail: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749

^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2003-09-25 19:16 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-09-25 18:51 weird(to me) request Larry Rosenman <ler@lerctr.org>
2003-09-25 18:59 ` Adam Wieckowski <adam-wieckowski@tlen.pl>
2003-09-25 19:02   ` Larry Rosenman <ler@lerctr.org>
2003-09-25 19:09 ` Richard Huxton <dev@archonet.com>
2003-09-25 19:16   ` Larry Rosenman <ler@lerctr.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox