Thread: pl/pgsql in a script?

pl/pgsql in a script?

From
"Tyler Hains"
Date:

Is it possible to run pl/pgsql in a script, without putting it into a function? I need to run a one-time update to my db. I could easily create a function run it and then drop it, but I’m wondering if I can just skip the function creation... Here’s what I’m trying to do...

 

DECLARE

    emp RECORD;

    db_id INTEGER;

BEGIN

    db_id := get_db_id();

 

    FOR emp IN SELECT email, min(password_sha256) AS pwd, min(external_id) as ext_id FROM employees WHERE coalesce(email, '') != '' AND priv_admin_sign_in = true group by email

    LOOP

                PERFORM dblink_exec('dbname=system', 'insert into logins

                  (email, external_id, password_sha256, database_id)

                  VALUES ('''||emp.email||''', '''||emp.ext_id||''', '''||emp.pwd||''', '||db_id||');');

    END LOOP;

END;

$$ LANGUAGE plpgsql;

 

Thanks,

Tyler Hains

IT Director

ProfitPoint, Inc.

888-541-6789 x115

www.profitpointinc.com

 

cid:part1.03090701.06020405@profitpointinc.com

 

This e-mail contains information that may be confidential and/or proprietary. It is intended solely for the addressee. Access to this e-mail by anyone else is unauthorized. If you are not the intended recipient of this transmission, any disclosure, copying, use, or distribution of the information included in this e-mail and any attachments is strictly prohibited. If you have received this transmission in error, please notify us by reply e-mail immediately and permanently delete this e-mail and any attachments. Thank you.

 

Attachment

Re: pl/pgsql in a script?

From
Tom Lane
Date:
"Tyler Hains" <thains@profitpointinc.com> writes:
> Is it possible to run pl/pgsql in a script, without putting it into a
> function?

No, not in any existing PG release.  (The DO command in 9.0 will support
that.)

            regards, tom lane