On Sat, Sep 6, 2014 at 6:59 AM, Pavel Stehule <pavel.steh...@gmail.com> wrote:
> People can prepare a simple functions like you did:
> CREATE OR REPLACE FUNCTION user_list ()
> RETURNS SETOF id AS $$
> RETURN QUERY SELECT id FROM user WHERE .. some = $1
> $$ LANGUAGE plpgsql;
> CREATE OR REPLACE FUNCTION update_user(int)
> RETURNS void AS $$
> UPDATE user SET .. WHERE id = $1
> $$ LANGUAGE;
> And then use it in mass operations:
> FOR company IN SELECT * FROM company_list()
> FOR id IN SELECT * FROM user_list(company)
> END LOOP;
> Or use it in application same style.
> It is safe .. sure, and I accept it. But It is terrible slow.
The above is horrible and ugly. That's not how I write code.
Only for top-level functions, i.e. API-functions, is it motivated to
encapsulate even simple queries like that, but *never* in other
PL-functions, as that doesn't fulfil any purpose, putting simple
queries inside functions only make it less obvious what the code does
where you have a function call instead of a SQL-query.
Sent via pgsql-hackers mailing list (email@example.com)
To make changes to your subscription: