pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mulham freshcode <mulhamcode@yahoo.com>
To: aklaver@comcast.net
To: pgsql-sql@postgresql.org
Cc: Mulham freshcode <mulhamcode@yahoo.com>
Subject: Re: select into
Date: Mon, 27 Nov 2006 18:31:16 -0800 (PST)
Message-ID: <20061128023116.58151.qmail@web90509.mail.mud.yahoo.com> (raw)
In-Reply-To: <200611261823.44994.aklaver@comcast.net>

Hi Adrian,

Thanks very much for your help...it is a pity you can't do this in plpgsql coz i have almost every thing else I need, and I hate to use yet another language. What does it take to add this mechanism to the language? Is any one planning to add it? It can come it handy I bet.

Thanks again,

Mustafa...



Adrian Klaver <aklaver@comcast.net> wrote: On Sunday 26 November 2006 02:45 pm, Adrian Klaver wrote:

>
> I am afraid I can't make it work either.
I could not make it work with pl/pgsql, but I did manage to come up with a 
solution using pl/pythonu.
The function is as follows-

CREATE OR REPLACE FUNCTION dat_col_py(text) RETURNS text AS
$Body$
tbl_name=args[0]
cols=plpy.prepare("select column_name from information_schema.columns where\
table_name=$1",["text"])
clean=plpy.prepare("delete from dat_col where table_name=$1",["text"])
clean_tbl=plpy.execute(clean,[tbl_name])
ins=plpy.prepare("insert into dat_col values($1,$2,$3),["text","text","text"])
data_rs=plpy.execute('select * from '+tbl_name)
cols_rs=plpy.execute(cols,[tbl_name])
for i in range(len(data_rs)):
    for j in range(len(cols_rs)):
        plpy.execute(ins,(tbl_name,cols_rs[j]['column_name'],
        data_rs[i][cols_rs[j]['column_name'] ]))
$Body$
LANGUAGE plpythonu;

For this to work I created a table dat_col(table_name text,column_name 
text,column_data text). The function deletes old data from the table before 
it is run, based on table name. Just run as dat_col_py("table name"). This 
assumes you have pl/pythonu installed.
-- 
Adrian Klaver 
aklaver@comcast.net

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match


 
---------------------------------
Cheap Talk? Check out Yahoo! Messenger's low PC-to-Phone call rates.

view thread (43+ messages)  latest in thread

Message-ID: <20061128023116.58151.qmail@web90509.mail.mud.yahoo.com>
Permalink:  ../20061128023116.58151.qmail@web90509.mail.mud.yahoo.com/
Also on:    postgresql.org/message-id/20061128023116.58151.qmail@web90509.mail.mud.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mulhamcode@yahoo.com, aklaver@comcast.net
  Subject: Re: select into
  In-Reply-To: <20061128023116.58151.qmail@web90509.mail.mud.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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