pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedquery and stored procedures
3+ messages / 3 participants
[nested] [flat]
* query and stored procedures
@ 2005-01-06 00:50 David Bear <David.Bear@asu.edu>
2005-01-06 02:12 ` Re: query and stored procedures Uwe C. Schroeder <uwe@oss4u.com>
2005-01-06 03:14 ` Re: query and stored procedures Joshua D. Drake <jd@commandprompt.com>
0 siblings, 2 replies; 3+ messages in thread
From: David Bear @ 2005-01-06 00:50 UTC (permalink / raw)
To: pgsql-admin
I'm so totally new to postgresql that I'm not sure how to word this.
I want to create a query, that does two things
1) take input in the form of a string of numbers, and test if
a) is ssn
b) or internal id
if the string is an ssn, make a second query to another data base,
asking it to convert the ssn to our internal id
otherwise,
2) use the id given to query an existing table
I'm not sure what feature/function postgresql has to help me do this.
I'd like to stick with using python as my language, and I'm guessing
this would be stored procedure, but I'm too new to know.
Please point me to some good reading.
--
David Bear
phone: 480-965-8257
fax: 480-965-9189
College of Public Programs/ASU
Wilson Hall 232
Tempe, AZ 85287-0803
"Beware the IP portfolio, everyone will be suspect of trespassing"
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: query and stored procedures
2005-01-06 00:50 query and stored procedures David Bear <David.Bear@asu.edu>
@ 2005-01-06 02:12 ` Uwe C. Schroeder <uwe@oss4u.com>
1 sibling, 0 replies; 3+ messages in thread
From: Uwe C. Schroeder @ 2005-01-06 02:12 UTC (permalink / raw)
To: David.Bear@asu.edu; pgsql-admin
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Well, I'd use pgsql - as a quick idea you could use something like:
CREATE OR REPLACE FUNCTION checkssn(varchar)
RETURNS SETOF whatever_your_table AS
'
DECLARE
incoming_ssn ALIAS FOR $1;
result whatever_your_table%ROWTYPE;
my_internal_id VARCHAR;
BEGIN
-- check if this is a ssn or internal id
SELECT INTO my_internal_id internal_id FROM whatever_your_table WHERE internal_id=incoming_ssn;
IF NOT FOUND THEN
-- probably a ssn, so the above doesnt hit anything
SELECT INTO my_internal_id internal_id FROM other_table WHERE ssn=incoming_ssn;
IF NOT FOUND THEN
RAISE EXCEPTION ''SSN not found!'';
END IF;
END IF;
-- since this one returns SETOF you have to loop over the result, even if its just one
FOR result IN SELECT * FROM whatever_your_table WHERE internal_id=my_internal_id LOOP
RETURN NEXT result;
END LOOP;
RETURN;
END;
' LANGUAGE 'plpgsql' VOLATILE;
Hope that helps
UC
On Wednesday 05 January 2005 04:50 pm, David Bear wrote:
> I'm so totally new to postgresql that I'm not sure how to word this.
>
> I want to create a query, that does two things
>
> 1) take input in the form of a string of numbers, and test if
> a) is ssn
> b) or internal id
>
> if the string is an ssn, make a second query to another data base,
> asking it to convert the ssn to our internal id
>
> otherwise,
>
> 2) use the id given to query an existing table
>
> I'm not sure what feature/function postgresql has to help me do this.
> I'd like to stick with using python as my language, and I'm guessing
> this would be stored procedure, but I'm too new to know.
>
> Please point me to some good reading.
- --
Open Source Solutions 4U, LLC 2570 Fleetwood Drive
Phone: +1 650 872 2425 San Bruno, CA 94066
Cell: +1 650 302 2405 United States
Fax: +1 650 872 2417
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQFB3J6YjqGXBvRToM4RAi1MAJ4oNUtL1AXq90c5OCYvcECAn22O9ACgshMB
jT19mmCz4nHRbCjy07/wCq0=
=DVA8
-----END PGP SIGNATURE-----
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: query and stored procedures
2005-01-06 00:50 query and stored procedures David Bear <David.Bear@asu.edu>
@ 2005-01-06 03:14 ` Joshua D. Drake <jd@commandprompt.com>
1 sibling, 0 replies; 3+ messages in thread
From: Joshua D. Drake @ 2005-01-06 03:14 UTC (permalink / raw)
To: David.Bear@asu.edu; +Cc: pgsql-admin
David Bear wrote:
>I'm so totally new to postgresql that I'm not sure how to word this.
>
>
>
What you want to do is create a function (store procedure)...
You can use plpythonu to do what you want. So you could create
something like this:
create or replace function check_id(text) returns integer as ...
Sincerely,
Joshua D. Drake
>I want to create a query, that does two things
>
>1) take input in the form of a string of numbers, and test if
> a) is ssn
> b) or internal id
>
>if the string is an ssn, make a second query to another data base,
>asking it to convert the ssn to our internal id
>
>otherwise,
>
>2) use the id given to query an existing table
>
>I'm not sure what feature/function postgresql has to help me do this.
>I'd like to stick with using python as my language, and I'm guessing
>this would be stored procedure, but I'm too new to know.
>
>Please point me to some good reading.
>
>
>
--
Command Prompt, Inc., home of Mammoth PostgreSQL - S/ODBC and S/JDBC
Postgresql support, programming shared hosting and dedicated hosting.
+1-503-667-4564 - jd@commandprompt.com - http://www.commandprompt.com
PostgreSQL Replicator -- production quality replication for PostgreSQL
Attachments:
jd.vcf (text/x-vcard, 283B) download
begin:vcard
fn:Joshua Drake
n:Drake;Joshua
org:Command Prompt, Inc.
adr:;;PO Box 215 ;Cascade Locks;OR;97014;US
email;internet:jd@commandprompt.com
title:Consultant
tel;work:503-667-4564
tel;fax:503-210-0334
x-mozilla-html:FALSE
url:http://www.commandprompt.com
version:2.1
end:vcard
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2005-01-06 03:14 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-01-06 00:50 query and stored procedures David Bear <David.Bear@asu.edu>
2005-01-06 02:12 ` Uwe C. Schroeder <uwe@oss4u.com>
2005-01-06 03:14 ` Joshua D. Drake <jd@commandprompt.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox