From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
---|---|
To: | David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com> |
Cc: | PostgreSQL General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: if row has property X, find all rows that has property X |
Date: | 2014-06-24 15:37:22 |
Message-ID: | CAHyXU0zKZNeoT5dQ7KZ0P7qiDNPW-=PQXTk5LRg=N7vtkZmJFg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Tue, Jun 24, 2014 at 8:40 AM, David G Johnston
<david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
> Дмитрий Голубь wrote
>> For example I have table addresses and usually I want 2 things:
>> 1. Find id of bad addresses.
>> 2. Check if this address is good or bad.
>>
>> For this I write two plpgsql functions
>> 1. find_all_bad_addresses
>> 2. is_bad_address(id)
>>
>> These functions will duplicate logic of each other. How to not repeat
>> myself?
>
> You can call other functions while inside a function......
>
> CREATE FUNCTION do_a() ... $$ do_something; $$
> CREATE FUNCTION do_b() ... $$ do_a(); $$
I'd consider making 'bad address' a view:
CREATE VIEW bad_address AS
SELECT * FROM Property
WHERE ...
Then just reference that in relevant code.
merlin
From | Date | Subject | |
---|---|---|---|
Next Message | pgdude | 2014-06-24 16:04:45 | Re: Weird error when setting up streaming replication |
Previous Message | John Lumby | 2014-06-24 15:08:55 | Re: Extended Prefetching using Asynchronous IO - proposal and patch |