pl/pgsql in a script?

From: "Tyler Hains" <thains(at)profitpointinc(dot)com>
To: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: pl/pgsql in a script?
Date: 2010-06-08 21:19:26
Message-ID: H000006900c06471.1276031964.mailpa.profitpointinc.com@MHS
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

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(dot)03090701(dot)06020405(at)profitpointinc(dot)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.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2010-06-08 22:39:20 Re: pl/pgsql in a script?
Previous Message Jon Jensen 2010-06-08 15:35:14 Re: The Two Towers