Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id B54361EC5BE7 for ; Thu, 2 Feb 2012 11:16:52 -0400 (AST) Received: from plane.gmane.org ([80.91.229.3]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RsyOw-0004K4-81 for pgsql-sql@postgresql.org; Thu, 02 Feb 2012 15:16:48 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1RsyOj-0008Lc-3M for pgsql-sql@postgresql.org; Thu, 02 Feb 2012 16:16:29 +0100 Received: from ip-118-90-88-42.xdsl.xnet.co.nz ([118.90.88.42]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 02 Feb 2012 16:16:29 +0100 Received: from jasen by ip-118-90-88-42.xdsl.xnet.co.nz with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 02 Feb 2012 16:16:29 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Jasen Betts Subject: Re: MS-SQL Store Procedure to Postgresql Function Date: 1 Feb 2012 10:52:41 GMT Organization: Dis (not Dat) Organisation Lines: 57 Message-ID: References: <1327905771.73991.YahooMailNeo@web121606.mail.ne1.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: ip-118-90-88-42.xdsl.xnet.co.nz X-Face: ?)Aw4rXwN5u0~$nqKj`xPz>xHCwgi^q+^?Ri*+R(&uv2=E1Q0Zk(>h!~o2ID@6{uf8s; a +M[5[U[QT7xFN%^gR"=tuJw%TXXR'Fp~W; (T"1(739R%m0Yyyv*gkGoPA.$b,D.w:z+<'"=-lVT?6 {T?=R^:W5g|E2#EhjKCa+nt":4b}dU7GYB*HBxn&Td$@f%.kl^:7X8rQWd[NTc"P"u6nkisze/Q; 8 "9Z{peQF,w)7UjV$c|RO/mQW/NMgWfr5*$-Z%u46"/00mx-,\R'fLPe.)^ User-Agent: slrn/pre1.0.0-18 (Linux) X-Pg-Spam-Score: -0.6 (/) X-Archive-Number: 201202/9 X-Sequence-Number: 36302 On 2012-01-30, Rehan Saleem wrote: >hi , how i can convert this store procedure to PostgreSQL function, >especially I really dont know how to set type to readonly in PostgreSQL. >thanksUserACUserAC I don't actually understand T-SQL so I'm going from the structure more than from the actual meaning of the code given it looks like the same effect could be had in a different way "delete ... using" instead. this is assuming that you set up a cascading delete of UserAccountDetails assuming the thie makes sense: ALTER TABLE UserAC ADD PRIMARY KEY(UserDataAcountId); -- the important part is UserAC.UserDataAcountId has an index -- with the unique property, I'm guessing id is actually a primary key. ALTER TABLE UserAccountDetails ADD UserDataAcountId REFERENCES UserAC(UserDataAcountId) ON DELETE CASCADE; -- again i'm guessing from the names of the columns. -- nut if that all fits your data, and usage patterns -- you can do the following: DELETE FROM UserAC USING /*some-query*/ WHERE /*some-condition*/; and get pretty-much the same effect. here /*some-query*/ would be your table expression and /*some-condition*/ would join it to UserAC postgresql treats all unquoted identifiers as lower case, if you are have stuff with mixed-case names you need to quote them with double quotes, I have assumend that the mixed case is just for menmonic reasons and not significant. although postgres doesn't do table parameters there are three other possibilities, dynamic sql refcursors agregate functions. thses are all considered advanced topics, expect EVERYTHING that is not covered by SQL standards to be totally different, there is usually a way to do what you want, it may well be completely different to the old way. -- ⚂⚃ 100% natural