Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 4915018109FD for ; Fri, 2 Mar 2012 07:23:18 -0400 (AST) Received: from nm21.bullet.mail.ne1.yahoo.com ([98.138.90.84]) by makus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1S3QZx-0000Qp-1L for pgsql-sql@postgresql.org; Fri, 02 Mar 2012 11:23:17 +0000 Received: from [98.138.90.50] by nm21.bullet.mail.ne1.yahoo.com with NNFMP; 02 Mar 2012 11:23:04 -0000 Received: from [98.138.226.164] by tm3.bullet.mail.ne1.yahoo.com with NNFMP; 02 Mar 2012 11:23:04 -0000 Received: from [127.0.0.1] by omp1065.mail.ne1.yahoo.com with NNFMP; 02 Mar 2012 11:23:04 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 217697.14246.bm@omp1065.mail.ne1.yahoo.com Received: (qmail 49563 invoked by uid 60001); 2 Mar 2012 11:23:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1330687384; bh=R6piYeCRj38Cc6jeANn2gf1iETHEbmdgawmcnTAiuJY=; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=rNDzpGEOJ2ef34s5FuAds6SP/39z3YfSi6Lxinan+UCzvsmURMgGU7TYae2i0IBj6W49S5y5VMbP/03+02+qFHOIGs5NrcK9GSls0rvDl9Kp0t7DpBEZcSL2TYUre3C67xGFWnCojQ3wLbQpuKm9IWjsQN4Z0LgmR2YDyaix6hc= 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=xTtE4QnXV9oDfdFGLkII5kiSPUtdkSCP0oRMP/HglIG3dBx2K9eF9GH69jr05HTUGSGxfDOmP67m4Fgqpz7LLztWBnncpNDx4VjoO2LiaNpqpU+iSnX56veZXKs9ePAhJiEB0SlI/ggJwcsck4QYoG3Nx3+jqfL17gr3lv55r1A=; X-YMail-OSG: WIM87hMVM1neRvfVno571Hiu462O7iIOIzDm6iUsiyUVYXC UQAEIHQLy0sXCiXWJn_KrD0qP_BhRznBVkYAJsDZr6OqLk7mntpUTIac1dBx FK9tD39.vNFtgavgcWBNbuTZXeBshJIKc4GLqzRIzcrqlul1XCADy2SZGZXm nrmE2EkKRGh7i5ZVDyfPViQkZJw_V38JvjhvMRAUzcvlWlQlmqu3Q574CCGC PETv5sFIVbwOGQEPv0q1y1RSBcnPix8x8ZEKW7SydxxcWORXjf_TmnO5zJnn Q3476BIt..UJlZB75K0Jtma7cz6C_7n1lrz7y7loM_4e8BvEzmYW4RIJ_a8w Xgju9ctLbcJC_h1eJDSTgNhOOTeN__JtUfE4fnZ86N9R8oV3qw9HMsd_hzvQ jnxgG6j7S.fYEmwt9lARxyHaziLcSXOEhYOyVII.Mtp4L1569bFLZvJ2GfJ1 9zuGxlA-- Received: from [182.177.152.160] by web121602.mail.ne1.yahoo.com via HTTP; Fri, 02 Mar 2012 03:23:03 PST X-Mailer: YahooMailWebService/0.8.116.338427 Message-ID: <1330687383.77274.YahooMailNeo@web121602.mail.ne1.yahoo.com> Date: Fri, 2 Mar 2012 03:23:03 -0800 (PST) From: Rehan Saleem Reply-To: Rehan Saleem Subject: How To Create Temporary Table inside a function To: "pgsql-sql@postgresql.org" MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-2038480821-1756694682-1330687383=:77274" X-Pg-Spam-Score: 3.9 (+++) X-Archive-Number: 201203/16 X-Sequence-Number: 36411 ---2038480821-1756694682-1330687383=:77274 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable hi everyone ,=0Ahow can i create temp table say table1 with three column of= types varchar , int and int, inside the function body and if that same tab= le already=A0exist=A0it should drop that already existing table(table1) , a= nd on every run this process should run. and how can i insert values from p= ostgresql view say vwfirst to this table(table1)=0A=0AHere is the MS-SQL co= de for this process but =A0i want to know how can this be done in postgresq= l=0A=0Aif object_id('tempdb..#tblTFSites1') is not null=0A=A0 drop table te= mpdb..#tblTFSites1=0A=0Acreate table #tblTFSites1(=0A Chr varchar(50) NULL,= =0A Start int NULL,=0A [End] int NULL=0A)=0A=0AINSERTION PROCESS=0A=0AINSER= T INTO #tblTFSites1 (Chr, Start,[End])=0ASelect Chr_U, Start_U, End_U from = vwChrCompareSites where KBId=3D@ID and UserDataDetailId=3D@UserDataDetailId= =A0=0Aand bpOverlap >=3D @bpOverlap and (CentreDistance <=3D @CentreDistanc= e or @CentreDistance=3D1) ---2038480821-1756694682-1330687383=:77274 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
hi ev= eryone ,
how can i create temp table say table1 with three column of t= ypes varchar , int and int, inside the function body and if that same table= already exist it should drop that already existing table(table1) , and = on every run this process should run. and how can i insert values from post= gresql view say vwfirst to this table(table1)

Here is the MS-SQL code for this process but  i want to know how can this be done= in postgresql

if object_id('tempdb..#tbl= TFSites1') is not null
  drop table tempdb..#tblTFSites1

create table #tblTFSites1(
=09 Chr varchar(50) NULL,
=09 Start int NULL,
=09 [End] int NULL
)

IN= SERTION PROCESS

INSERT INTO #tblTFSites1 (Chr= , Start,[End])
=09=09Select Chr_U, Start_U, End_U from vwChrCompareSites whe= re KBId=3D@ID and UserDataDetailId=3D@UserDataDetailId 
=09=09=09and bpOverlap >=3D @= bpOverlap and (CentreDistance <=3D @CentreDistance or @CentreDistance=3D= 1)


---2038480821-1756694682-1330687383=:77274--