Lists: | pgsql-sql |
---|
From: | Larry Rosenman <ler(at)lerctr(dot)org> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | weird(to me) request |
Date: | 2003-09-25 18:51:28 |
Message-ID: | 294260000.1064515888@lerlaptop-red.iadfw.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | 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(at)lerctr(dot)org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749
From: | Adam Wieckowski <adam-wieckowski(at)tlen(dot)pl> |
---|---|
To: | Larry Rosenman <ler(at)lerctr(dot)org> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: weird(to me) request |
Date: | 2003-09-25 18:59:25 |
Message-ID: | 3F733B0D.5050801@tlen.pl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | 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 ?
From: | Larry Rosenman <ler(at)lerctr(dot)org> |
---|---|
To: | Adam Wieckowski <adam-wieckowski(at)tlen(dot)pl> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: weird(to me) request |
Date: | 2003-09-25 19:02:04 |
Message-ID: | 311350000.1064516524@lerlaptop-red.iadfw.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
--On Thursday, September 25, 2003 20:59:25 +0200 Adam Wieckowski
<adam-wieckowski(at)tlen(dot)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(at)lerctr(dot)org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749
From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | Larry Rosenman <ler(at)lerctr(dot)org>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: weird(to me) request |
Date: | 2003-09-25 19:09:35 |
Message-ID: | 200309252009.35449.dev@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | 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
From: | Larry Rosenman <ler(at)lerctr(dot)org> |
---|---|
To: | Richard Huxton <dev(at)archonet(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: weird(to me) request |
Date: | 2003-09-25 19:16:53 |
Message-ID: | 324780000.1064517413@lerlaptop-red.iadfw.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
--On Thursday, September 25, 2003 20:09:35 +0100 Richard Huxton
<dev(at)archonet(dot)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(at)lerctr(dot)org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749