From pk_rehan@yahoo.com Wed Jan 18 09:03:36 2012 Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 4E23E86A549 for ; Wed, 18 Jan 2012 05:03:36 -0400 (AST) Received: from nm20-vm4.bullet.mail.ne1.yahoo.com ([98.138.91.180]) by makus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1RnRQc-0005YE-Sl for pgsql-sql@postgresql.org; Wed, 18 Jan 2012 09:03:35 +0000 Received: from [98.138.90.55] by nm20.bullet.mail.ne1.yahoo.com with NNFMP; 18 Jan 2012 09:03:22 -0000 Received: from [98.138.89.234] by tm8.bullet.mail.ne1.yahoo.com with NNFMP; 18 Jan 2012 09:03:22 -0000 Received: from [127.0.0.1] by omp1049.mail.ne1.yahoo.com with NNFMP; 18 Jan 2012 09:03:22 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 402670.5183.bm@omp1049.mail.ne1.yahoo.com Received: (qmail 51226 invoked by uid 60001); 18 Jan 2012 09:03:22 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1326877402; bh=5qZgqZ6lAYSJC8WGFK9sR97dq8s77K3s8pRcDIR6BSo=; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=O2c5HooFNQu2KZuoC/WFWhDwFjKfHgQUvGFO5uG8dkLudiK4uewrrQkjQpbPXp2e3mfkZl68tfVgl4wSlDbiHO7nPmc7cOcfL0Yx/KVPU9i+D5Y7ZEjR1FXvR9hCENPfdPrsFKimv97BauWHDUDc6yfzmDV2Irt9HHvk+DTHFgw= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=obVLRgCUzjqJFnQFRe0bF7W0J2/S9NM0Pj2Aqx1KQmVHxqPh4s/aeCaAdL9OO/gCBgq0hzeDYa7DqKCiUg3JSaUpRYk/Kq96Jlrjv00hYHcX/TzG0xgcCSXgKaH3KE+7L9DF0ecr0FDCTLvse8HAMpcwbgE0axvmxZ6Kgqqy2pA=; X-YMail-OSG: t1DKXjEVM1ltv9P75qZTPSkWnsKMbuu6Q5Y0SL88Y4x0kYI WRg6HQh4YTijjOfnb.DkDg9s8EpsjIj1fCu3F_0.YaSwue2nWrMT.SKCdbXM OP0FDjDtWb8EgAjZmfAoZ9IZ6nLc4ZvyQaw2bnxI3gUz3e6mlnVBtZhM3kFS tcEXHXfVZ7aHsrTO15jvB.f_J0gneFSjiJK_3a4l1fg0ciomvTaNcIwd7rll SnbIeHxTpkTehKxa70X7l9My6I5Llyxuy0Lfs7hs4hlNa4Co6MRaFTPwT2IF _fwg.EiRq08ZL15MxNQCd7tBwFj_jGidNLJSxegLMpdmfqTlVLuTCPslFcdQ OVMjkiUy41ywEzuXDJOQLEZQagQcxi9Um11Z_o_qdK0jr80Sa4aza3YgzDVs xK55.G_tYqRO7aL2QUyCfNo28OWcGYABd1_OJrtGg7CC7nw-- Received: from [180.178.172.138] by web121605.mail.ne1.yahoo.com via HTTP; Wed, 18 Jan 2012 01:03:22 PST X-Mailer: YahooMailWebService/0.8.115.331698 Message-ID: <1326877402.34750.YahooMailNeo@web121605.mail.ne1.yahoo.com> Date: Wed, 18 Jan 2012 01:03:22 -0800 (PST) From: Rehan Saleem Reply-To: Rehan Saleem Subject: Postgresql Function To: "pgsql-sql@postgresql.org" MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="2053635335-888544061-1326877402=:34750" X-Pg-Spam-Score: 0.8 (/) X-Archive-Number: 201201/81 X-Sequence-Number: 36252 --2053635335-888544061-1326877402=:34750 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable hi=A0=0Ai want to create a function in postgresql that take input for colum= ns from user for example first_name , last_name, addres. and will put them = into table , and i also want to use exception if user enters wrong data. wi= ll some one help me how can i create thats function , because i am new to p= ostgresql . i know how to do it in MS-SQL , i also have that code .if you d= ont understand what am trying to say . i can post sql code .thanks=0AREHAN = SALEEM=A0 --2053635335-888544061-1326877402=:34750 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
hi 
= i want to create a function in postgresql that take input for columns from = user for example first_name , last_name, addres. and will put them into tab= le , and i also want to use exception if user enters wrong data. will some = one help me how can i create thats function , because i am new to postgresq= l . i know how to do it in MS-SQL , i also have that code .if you dont unde= rstand what am trying to say . i can post sql code .thanks
REHAN SALEEM 
--2053635335-888544061-1326877402=:34750-- From pk_rehan@yahoo.com Wed Jan 18 09:10:58 2012 Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 1529C86A54A for ; Wed, 18 Jan 2012 05:10:58 -0400 (AST) Received: from nm5-vm3.bullet.mail.ne1.yahoo.com ([98.138.91.135]) by magus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1RnRXk-0004TQ-PG for pgsql-sql@postgresql.org; Wed, 18 Jan 2012 09:10:58 +0000 Received: from [98.138.90.57] by nm5.bullet.mail.ne1.yahoo.com with NNFMP; 18 Jan 2012 09:10:42 -0000 Received: from [98.138.89.164] by tm10.bullet.mail.ne1.yahoo.com with NNFMP; 18 Jan 2012 09:10:42 -0000 Received: from [127.0.0.1] by omp1020.mail.ne1.yahoo.com with NNFMP; 18 Jan 2012 09:10:42 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 579043.75912.bm@omp1020.mail.ne1.yahoo.com Received: (qmail 18738 invoked by uid 60001); 18 Jan 2012 09:10:42 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1326877842; bh=Ks6fhpjF7G1rLmfibc+OCjG/EldBVH7n0gVlnSUqVe8=; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=aQOOvUy1PUI5aMgsO1bW1e11Ex6SVuDQzMRBLPpqTdVlDP5V//EaPE2tsPfKRQtb9vLz+Hw7oZdHSxw/OraVdvZyMBeP4zUqZxdgvppR1g7Nui46KF+DN0rpbsHJbd+xZZ6l8HXqfiu53akMSaizQosKFTbFaewwtf4aVnvJncQ= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=uyGct1m9jztYX9/w1fWX6iMW4BAIdGqgwiAIJ3pm0LDESedk48z1pSWuJaiIf7MDRs/qf9FXJMiAk1o1BfaaDmIa6uKyEQvExsVfAS20v2+ULj0NqQ4ubCqomke5RRhG3ZbU1AdG5E05ScXNfdZv2KFFisp82RigGplBRmDEKxM=; X-YMail-OSG: MjNnTXwVM1mU5GixWny5pZccCC3Qm7WxFo3WJ3HuQn3cAJH xQbTg0A5CIEjwcPrPDOtonaaodeHh7edMI.ybqNVbWGY1gtR6aAvZ4C5A32G 3DH2ZHQKSCcubkeWfoNOfzraeoewKWbu4R4wpWR8NwQ.rQkaSvZe1fgwTTzv 1Bu6ia5PuO3CKA9fnrbm73u3xA6Fbx4qME8KX55ldn.alpfML.AaOL36dEeL uA539ZhAV8cgbr4D8VypDLM8IE8NzcA4YY4CIdEXb3tR4qzQ1BELrqqDHF6n O6CeaqhFdvOW8DkeGAD0ZwTRrV42XgkEtbqvKUt4j3qSbCXMQPrpWWjuAwN4 6bV6GHehVEPaKppu2FbxQwgoYAuvNErJnYk3B_9tpaoTFJDw88KQC7WmSELR bJGrE5tRnPUWI_QVXqvcZV7hipJWQHPZvDmH27ApC_8bjhWLAsAH5NMLThy3 L_oLGgctkg_YfO51eECGk1VEb5Rjfqmj.9oLspLTASL7Nu4R9.g-- Received: from [180.178.172.138] by web121606.mail.ne1.yahoo.com via HTTP; Wed, 18 Jan 2012 01:10:42 PST X-Mailer: YahooMailWebService/0.8.115.331698 Message-ID: <1326877842.18699.YahooMailNeo@web121606.mail.ne1.yahoo.com> Date: Wed, 18 Jan 2012 01:10:42 -0800 (PST) From: Rehan Saleem Reply-To: Rehan Saleem Subject: PostgreSQL Function To: "pgsql-sql@postgresql.org" MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="1458340343-1666219641-1326877842=:18699" X-Pg-Spam-Score: 0.7 (/) X-Archive-Number: 201201/82 X-Sequence-Number: 36253 --1458340343-1666219641-1326877842=:18699 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable hi=A0=0Ai want to create a function in postgresql that take input for colum= ns from user for example first_name , last_name, addres. and will put them = into table , and i also want to use exception if user enters wrong data. wi= ll some one help me how can i create thats function , because i am new to p= ostgresql . i know how to do it in MS-SQL , i also have that code .if you d= ont understand what am trying to say . i can=A0post=A0sql code .thanks =0A --1458340343-1666219641-1326877842=:18699 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
hi 
= i want to create a function in postgresql that take input for columns from = user for example first_name , last_name, addres. and will put them into tab= le , and i also want to use exception if user enters wrong data. will some = one help me how can i create thats function , because i am new to postgresq= l . i know how to do it in MS-SQL , i also have that code .if you dont unde= rstand what am trying to say . i can post sql code .thanks
<= /div>

--1458340343-1666219641-1326877842=:18699-- From pavel.stehule@gmail.com Wed Jan 18 09:26:24 2012 Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 081FE86A549 for ; Wed, 18 Jan 2012 05:26:24 -0400 (AST) Received: from mail-qw0-f53.google.com ([209.85.216.53]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RnRmf-0004j4-VW for pgsql-sql@postgresql.org; Wed, 18 Jan 2012 09:26:23 +0000 Received: by qabg24 with SMTP id g24so50580qab.19 for ; Wed, 18 Jan 2012 01:26:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=gVtgsT8zRxMihsLlrepJKto3kJMjqepF950XcFUIJGo=; b=L3PBy4kiU08wyysBxABjzIshOIaEvbQhypqpyzKK2YaS3fqnZJFsk0FN/AwzBktJQ9 8Jwps/dNnfFOCDiCVr1cdBSv7ALrp8Rzax9SKb6knAGNZ/aAOi5ZJQ8wb8wJ5PoxCSkJ p65VUlgAFkxKM1eO9lbS35TNXbvczXYqo3R6I= Received: by 10.224.216.74 with SMTP id hh10mr20549965qab.45.1326878768481; Wed, 18 Jan 2012 01:26:08 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.248.70 with HTTP; Wed, 18 Jan 2012 01:25:27 -0800 (PST) In-Reply-To: <1326877842.18699.YahooMailNeo@web121606.mail.ne1.yahoo.com> References: <1326877842.18699.YahooMailNeo@web121606.mail.ne1.yahoo.com> From: Pavel Stehule Date: Wed, 18 Jan 2012 10:25:27 +0100 Message-ID: Subject: Re: PostgreSQL Function To: Rehan Saleem Cc: "pgsql-sql@postgresql.org" Content-Type: multipart/alternative; boundary=20cf300514a2a7c44404b6ca091f X-Pg-Spam-Score: -2.7 (--) X-Archive-Number: 201201/83 X-Sequence-Number: 36254 --20cf300514a2a7c44404b6ca091f Content-Type: text/plain; charset=UTF-8 Hello 2012/1/18 Rehan Saleem > hi > i want to create a function in postgresql that take input for columns from > user for example first_name , last_name, addres. and will put them into > table , and i also want to use exception if user enters wrong data. will > some one help me how can i create thats function , because i am new to > postgresql . i know how to do it in MS-SQL , i also have that code .if you > dont understand what am trying to say . i can post sql > code .thanks > > CREATE TABLE users(id serial PRIMARY KEY, first_name varchar(10), last_name varchar(10)); CREATE OR REPLACE FUNCTION new_user(fname varchar, lname varchar) RETURNS int AS $$ DECLARE r int; BEGIN -- custom exception -- lname cannot be empty or NEMO IF trim(lname) = '' OR lower(lname) = 'nemo' THEN RAISE EXCEPTION 'bad last_name: "%"', lname; END IF; INSERT INTO users(first_name, last_name) VALUES(lname, fname) RETURNING id INTO r; RETURN r; END; $$ LANGUAGE plpgsql; postgres=# select new_user('pavel','stehule'); new_user ---------- 1 (1 row) postgres=# select new_user('pavel','very long text'); ERROR: value too long for type character varying(10) CONTEXT: SQL statement "INSERT INTO users(first_name, last_name) VALUES(lname, fname) RETURNING id" PL/pgSQL function "new_user" line 8 at SQL statement postgres=# select new_user('pavel','nemo'); ERROR: bad last_name: "nemo" postgres=# Regards Pavel Stehule --20cf300514a2a7c44404b6ca091f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello

2012/1/18 Rehan Saleem <pk_rehan@yahoo.com><= /span>
hi=C2=A0
i want to create a function in postgresql that take = input for columns from user for example first_name , last_name, addres. and= will put them into table , and i also want to use exception if user enters= wrong data. will some one help me how can i create thats function , becaus= e i am new to postgresql . i know how to do it in MS-SQL , i also have that= code .if you dont understand what am trying to say . i can=C2=A0post=C2=A0sql code .tha= nks

CREATE TABLE users(id serial PRIMARY KEY, first_name varchar(10), last_na= me varchar(10));

CREATE OR REPLACE FUNCTION new_user(fname varchar, = lname varchar)
RETURNS int AS $$
DECLARE r int;
BEGIN
=C2=A0 -- custom exception = -- lname cannot be empty or NEMO
=C2=A0 IF trim(lname) =3D '' OR= lower(lname) =3D 'nemo' THEN
=C2=A0=C2=A0=C2=A0 RAISE EXCEPTION= 'bad last_name: "%"', lname;
=C2=A0 END IF;
=C2=A0 INSERT INTO users(first_name, last_name) VALUES(ln= ame, fname) RETURNING id INTO r;
=C2=A0 RETURN r;
END;
$$ LANGUAGE= plpgsql;

postgres=3D# select new_user('pavel','stehule&= #39;);
=C2=A0new_user
----------
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 1
(1 row)
postgres=3D# select new_user('pavel','very long text');ERROR:=C2=A0 value too long for type character varying(10)
CONTEXT:=C2= =A0 SQL statement "INSERT INTO users(first_name, last_name) VALUES(lna= me, fname) RETURNING id"
PL/pgSQL function "new_user" line 8 at SQL statement
postgres= =3D# select new_user('pavel','nemo');
ERROR:=C2=A0 bad l= ast_name: "nemo"
postgres=3D#

Regards

Pavel Ste= hule
--20cf300514a2a7c44404b6ca091f--