select into
select into
От:
Mulham freshcode <mulhamcode@yahoo.com>
Дата:
Hi guys,
Am new to sql scripting so this might be a stupid question. Am getting an error while trying to do the following
SELECT INTO svc_data_rec * from svc_tbl_name where 'uid' = sub_id;
where svc_data_rec is defined as record and svc_tbl_name is a varchar that holds the name of a table and sub_id is another varchar. the error message is
ERROR: syntax error at or near "$1" at character 17
QUERY: SELECT * from $1 where 'uid' = $2
CONTEXT: PL/pgSQL function "foo" line 132 at select into variables
LINE 1: SELECT * from $1 where 'uid' = $2
where am i going wrong? it seems that the variables are not being substituted with their values correctly.
Thank you,
Sponsored Link
Mortgage rates near 39yr lows. $420,000 Mortgage for $1,399/mo - Calculate new house payment
Re: select into
От:
"A. Kretschmer" <andreas.kretschmer@schollglas.com>
Дата:
am Wed, dem 22.11.2006, um 0:28:15 -0800 mailte Mulham freshcode folgendes: > Hi guys, > > Am new to sql scripting so this might be a stupid question. Am getting an > error while trying to do the following > > SELECT INTO svc_data_rec * from svc_tbl_name where 'uid' = sub_id; > > where svc_data_rec is defined as record and svc_tbl_name is a varchar that > holds the name of a table and sub_id is another varchar. the error message is You should rewrite your plpgsql-function. You can't handle with string-vars in this way, you must create a string with your complete sql and EXECUTE this string. Read http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47215, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
Re: select into
От:
Richard Broersma Jr <rabroersma@yahoo.com>
Дата:
> Hi guys, > > Am new to sql scripting so this might be a stupid question. Am getting an error while trying > to do the following > > SELECT INTO svc_data_rec * from svc_tbl_name where 'uid' = sub_id; > > where svc_data_rec is defined as record and svc_tbl_name is a varchar that holds the name of a > table and sub_id is another varchar. the error message is > > ERROR: syntax error at or near "$1" at character 17 > QUERY: SELECT * from $1 where 'uid' = $2 > CONTEXT: PL/pgSQL function "foo" line 132 at select into variables > LINE 1: SELECT * from $1 where 'uid' = $2 > > where am i going wrong? it seems that the variables are not being substituted with their > values correctly. Notice: http://www.postgresql.org/docs/8.2/interactive/sql-selectinto.html and particularly this example: http://www.postgresql.org/docs/8.2/interactive/sql-selectinto.html#AEN54014 Regards, Richard Broersma Jr.
Re: select into
От:
Andreas Kretschmer <akretschmer@spamfence.net>
Дата:
Richard Broersma Jr schrieb: > > Hi guys, > > > > Am new to sql scripting so this might be a stupid question. Am getting an error while trying > > to do the following > > > > SELECT INTO svc_data_rec * from svc_tbl_name where 'uid' = sub_id; > > > > where svc_data_rec is defined as record and svc_tbl_name is a varchar that holds the name of a > > table and sub_id is another varchar. the error message is > > > > ERROR: syntax error at or near "$1" at character 17 > > QUERY: SELECT * from $1 where 'uid' = $2 > > CONTEXT: PL/pgSQL function "foo" line 132 at select into variables > > LINE 1: SELECT * from $1 where 'uid' = $2 > > > > where am i going wrong? it seems that the variables are not being substituted with their > > values correctly. > > Notice: > http://www.postgresql.org/docs/8.2/interactive/sql-selectinto.html > and particularly this example: > http://www.postgresql.org/docs/8.2/interactive/sql-selectinto.html#AEN54014 > Regards, Richard, the plain SQL "INSERT INTO
Re: select into
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Mulham freshcode writes: > Am new to sql scripting so this might be a stupid question. Am getting an error while trying to do the following > SELECT INTO svc_data_rec * from svc_tbl_name where 'uid' = sub_id; The error message shows that this is getting rewritten into > QUERY: SELECT * from $1 where 'uid' = $2 so the problem is that you are using svc_tbl_name as a plpgsql variable, and plpgsql is not bright enough to realize that it shouldn't substitute the variable value at this particular spot in the query. You need to change the variable name to something that won't conflict. In general, don't use plpgsql variables that are named the same as any SQL tables or columns you need to mention in the function. regards, tom lane
Re: select into
От:
Richard Broersma Jr <rabroersma@yahoo.com>
Дата:
--- Andreas Kretschmer wrote: > Richard, the plain SQL "INSERT INTO
Re: select into
От:
Mulham freshcode <mulhamcode@yahoo.com>
Дата:
Hi,
Thanks very much for all the suggestions. Like Andreas said i have to use EXECUTE to do this. That was my guess too but i was putting the INTO cluase into the string before executing it. This is a step forward. The problem now is getting the into to work with a record. Am using a RECORD variable after declaring it in the INTO clause. pg is complaining
ERROR: record "svc_data_rec" is not assigned yet
DETAIL: The tuple structure of a not-yet-assigned record is indeterminate.
CONTEXT: PL/pgSQL function "foo" line 130 at execute statement
I read in the docs the following, "The INTO clause specifies where the results of a SELECT command should be assigned. If a row or variable list is provided, it must exactly match the structure of the results produced by the SELECT (when a record variable is used, it will configure itself to match the result's structure automatically)." That i take to mean that the above is ok. But it ain't.
Thanks again for your guys help...
"A. Kretschmer" <andreas.kretschmer@schollglas.com> wrote:am Wed, dem 22.11.2006, um 0:28:15 -0800 mailte Mulham freshcode folgendes:
> Hi guys,
>
> Am new to sql scripting so this might be a stupid question. Am getting an
> error while trying to do the following
>
> SELECT INTO svc_data_rec * from svc_tbl_name where 'uid' = sub_id;
>
> where svc_data_rec is defined as record and svc_tbl_name is a varchar that
> holds the name of a table and sub_id is another varchar. the error message is
You should rewrite your plpgsql-function. You can't handle with
string-vars in this way, you must create a string with your complete sql
and EXECUTE this string.
Read
http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN
Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47215, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly
Access over 1 million songs - Yahoo! Music Unlimited.
Re: select into
От:
Adrian Klaver <aklaver@comcast.net>
Дата:
On Thursday 23 November 2006 09:19 am, Mulham freshcode wrote: > Hi, > Thanks very much for all the suggestions. Like Andreas said i have to > use EXECUTE to do this. That was my guess too but i was putting the INTO > cluase into the string before executing it. This is a step forward. The > problem now is getting the into to work with a record. Am using a RECORD > variable after declaring it in the INTO clause. pg is complaining > > ERROR: record "svc_data_rec" is not assigned yet > DETAIL: The tuple structure of a not-yet-assigned record is > indeterminate. CONTEXT: PL/pgSQL function "foo" line 130 at execute > statement > > I read in the docs the following, "The INTO clause specifies where the > results of a SELECT command should be assigned. If a row or variable list > is provided, it must exactly match the structure of the results produced by > the SELECT (when a record variable is used, it will configure itself to > match the result's structure automatically)." That i take to mean that the > above is ok. But it ain't. > > Thanks again for your guys help... > > "A. Kretschmer" wrote: am Wed, dem 22.11.2006, um 0:28:15 -0800 mailte Mulham freshcode folgendes: > > Hi guys, > > > > Am new to sql scripting so this might be a stupid question. Am getting > > an error while trying to do the following > > > > SELECT INTO svc_data_rec * from svc_tbl_name where 'uid' = sub_id; > > > > where svc_data_rec is defined as record and svc_tbl_name is a varchar > > that holds the name of a table and sub_id is another varchar. the error > > message is > > You should rewrite your plpgsql-function. You can't handle with > string-vars in this way, you must create a string with your complete sql > and EXECUTE this string. > > Read > http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PLPG >SQL-STATEMENTS-EXECUTING-DYN > > > Andreas My guess is that the error message is correct, the svc_data_rec has not had any values assigned to it. In other words the EXECUTE statement is not working the way you think it is. Could you post the EXECUTE string? -- Adrian Klaver aklaver@comcast.net
Re: select into
От:
Mulham freshcode <mulhamcode@yahoo.com>
Дата:
Hello Adrian,
Here is my execute string,
sql_str1 = 'select * from ' || svc_tbl_name || ' where uid = ' || sub_id ;
execute sql_str1 into svc_data_rec ;
svc_data_rec is a RECORD, which is supposed to be dynamic. If I need to define the structure of the record then there will be no point in using it since I need something to change according the structure the table, which i don't know in advance...
Thank you,
Mustafa...
Adrian Klaver <aklaver@comcast.net> wrote:On Thursday 23 November 2006 09:19 am, Mulham freshcode wrote:
> Hi,
> Thanks very much for all the suggestions. Like Andreas said i have to
> use EXECUTE to do this. That was my guess too but i was putting the INTO
> cluase into the string before executing it. This is a step forward. The
> problem now is getting the into to work with a record. Am using a RECORD
> variable after declaring it in the INTO clause. pg is complaining
>
> ERROR: record "svc_data_rec" is not assigned yet
> DETAIL: The tuple structure of a not-yet-assigned record is
> indeterminate. CONTEXT: PL/pgSQL function "foo" line 130 at execute
> statement
>
> I read in the docs the following, "The INTO clause specifies where the
> results of a SELECT command should be assigned. If a row or variable list
> is provided, it must exactly match the structure of the results produced by
> the SELECT (when a record variable is used, it will configure itself to
> match the result's structure automatically)." That i take to mean that the
> above is ok. But it ain't.
>
> Thanks again for your guys help...
>
> "A. Kretschmer" wrote: am Wed, dem
22.11.2006, um 0:28:15 -0800 mailte Mulham freshcode folgendes:
> > Hi guys,
> >
> > Am new to sql scripting so this might be a stupid question. Am getting
> > an error while trying to do the following
> >
> > SELECT INTO svc_data_rec * from svc_tbl_name where 'uid' = sub_id;
> >
> > where svc_data_rec is defined as record and svc_tbl_name is a varchar
> > that holds the name of a table and sub_id is another varchar. the error
> > message is
>
> You should rewrite your plpgsql-function. You can't handle with
> string-vars in this way, you must create a string with your complete sql
> and EXECUTE this string.
>
> Read
> http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PLPG
>SQL-STATEMENTS-EXECUTING-DYN
>
>
> Andreas
My guess is that the error message is correct, the svc_data_rec has not had
any values assigned to it. In other words the EXECUTE statement is not
working the way you think it is. Could you post the EXECUTE string?
--
Adrian Klaver
aklaver@comcast.net
Want to start your own business? Learn how on Yahoo! Small Business.
Re: select into
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Mulham freshcode writes: > execute sql_str1 into svc_data_rec ; > svc_data_rec is a RECORD, which is supposed to be dynamic. This should work --- in PG 8.1 or later. In older versions you'd have to fool around with a FOR ... IN EXECUTE ... loop. regards, tom lane
Re: select into
От:
Mulham freshcode <mulhamcode@yahoo.com>
Дата:
Hi Tom,
Thanks for the help. Am using version 8.0 and it seems like RECORD is not that dynamic still. I tried with the FOR ... IN EXECUTE ... LOOP and it does the trick. But am still finding it hard to move forward with this. I have the name of table field in a varchar variable that i got from information_schema.columns and I have the records variable that stores the contains the data from that table. Usually I'd do something like data_rec.col_name to extract the data from the record but now I don't know the name per se. how can i say something like data_rec[col_name] where col_name is a variable that has the actual column name. I found no examples in the docs that explain this. Can it be done in version 8.0.1?
I find variable substitution kind of confusing. I mean why is there no way of saying explicitly replace this variable with its content before executing the statement?
Sorry for the long question,
and thanks again for the help
Mustafa...
Tom Lane <tgl@sss.pgh.pa.us> wrote:Mulham freshcode writes:
> execute sql_str1 into svc_data_rec ;
> svc_data_rec is a RECORD, which is supposed to be dynamic.
This should work --- in PG 8.1 or later. In older versions you'd have
to fool around with a FOR ... IN EXECUTE ... loop.
regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq
Everyone is raving about the all-new Yahoo! Mail beta.
Re: select into
От:
Adrian Klaver <aklaver@comcast.net>
Дата:
On Thursday 23 November 2006 08:45 pm, Tom Lane wrote: > Mulham freshcode writes: > > execute sql_str1 into svc_data_rec ; > > > > svc_data_rec is a RECORD, which is supposed to be dynamic. > > This should work --- in PG 8.1 or later. In older versions you'd have > to fool around with a FOR ... IN EXECUTE ... loop. > > regards, tom lane The documentation for pl/pgsql in 8.1 and higher says different. http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN " SELECT INTO is not currently supported within EXECUTE." The change is reflected in the HISTORY text though. How is the best way to get a change made to the documentation? -- Adrian Klaver aklaver@comcast.net
Re: select into
От:
Andreas Kretschmer <akretschmer@spamfence.net>
Дата:
Adrian Klaver schrieb: > On Thursday 23 November 2006 08:45 pm, Tom Lane wrote: > > Mulham freshcode writes: > > > execute sql_str1 into svc_data_rec ; > > > > > > svc_data_rec is a RECORD, which is supposed to be dynamic. > > > > This should work --- in PG 8.1 or later. In older versions you'd have > > to fool around with a FOR ... IN EXECUTE ... loop. > > > > regards, tom lane > The documentation for pl/pgsql in 8.1 and higher says different. > > http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN > " SELECT INTO is not currently supported within EXECUTE." Thats right. The solution with 8.1 or later is: EXECUTE .... INTO var, and _not_ SELECT INTO var. Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknow) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°
Re: select into
От:
Adrian Klaver <aklaver@comcast.net>
Дата:
On Friday 24 November 2006 06:55 am, Andreas Kretschmer wrote: > Adrian Klaver schrieb: > > On Thursday 23 November 2006 08:45 pm, Tom Lane wrote: > > > Mulham freshcode writes: > > > > execute sql_str1 into svc_data_rec ; > > > > > > > > svc_data_rec is a RECORD, which is supposed to be dynamic. > > > > > > This should work --- in PG 8.1 or later. In older versions you'd have > > > to fool around with a FOR ... IN EXECUTE ... loop. > > > > > > regards, tom lane > > > > The documentation for pl/pgsql in 8.1 and higher says different. > > > > http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PL > >PGSQL-STATEMENTS-EXECUTING-DYN " SELECT INTO is not currently supported > > within EXECUTE." > > Thats right. The solution with 8.1 or later is: > > EXECUTE .... INTO var, and _not_ SELECT INTO var. > > > Andreas Thanks for the information. Somewhere along the line I missed the distinction. -- Adrian Klaver aklaver@comcast.net
Re: select into
От:
Adrian Klaver <aklaver@comcast.net>
Дата:
On Thursday 23 November 2006 10:54 pm, Mulham freshcode wrote: > Hi Tom, > > Thanks for the help. Am using version 8.0 and it seems like RECORD is not > that dynamic still. I tried with the FOR ... IN EXECUTE ... LOOP and it > does the trick. But am still finding it hard to move forward with this. I > have the name of table field in a varchar variable that i got from > information_schema.columns and I have the records variable that stores the > contains the data from that table. Usually I'd do something like > data_rec.col_name to extract the data from the record but now I don't know > the name per se. how can i say something like data_rec[col_name] where > col_name is a variable that has the actual column name. I found no examples > in the docs that explain this. Can it be done in version 8.0.1? > > I find variable substitution kind of confusing. I mean why is there no way > of saying explicitly replace this variable with its content before > executing the statement? > > Sorry for the long question, > and thanks again for the help > > Mustafa... > > Tom Lane wrote: Mulham freshcode writes: > > execute sql_str1 into svc_data_rec ; > > > > svc_data_rec is a RECORD, which is supposed to be dynamic. > > This should work --- in PG 8.1 or later. In older versions you'd have > to fool around with a FOR ... IN EXECUTE ... loop. > > regards, tom lane > I am trying to sort this out. Are you trying to find the data for a single field from each table, or for some set of fields?. If you are looking for data from a single field couldn't you dispense with the RECORD variable and just build a query of the form SELECT col_name FROM tbl_name. If you want to go through a set of fields then it would involve some nested loops. -- Adrian Klaver aklaver@comcast.net
Re: select into
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Adrian Klaver writes: > On Thursday 23 November 2006 08:45 pm, Tom Lane wrote: >> This should work --- in PG 8.1 or later. > The documentation for pl/pgsql in 8.1 and higher says different. > http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN > " SELECT INTO is not currently supported within EXECUTE." That says you can't doEXECUTE 'select ... into foo ...'; which is not the same thing asEXECUTE 'select ...' into foo; regards, tom lane
Re: select into
От:
Mulham freshcode <mulhamcode@yahoo.com>
Дата:
Hi Adrian,
I have number of similar tables that have different number of fields (similar in functionality). An in my stored procedure am trying to select a row from one of these tables (that i don't know in advance, hence the use of record) and return the data in the form of a table that has column_name:value pairs. where column name is that from the original table. I have no problem finding the column names but I don't know how to say data[column_name] to get the corresponding value. Is there a way to do it in pgsql?
here is my code so far
sql_str1 = 'select * from ' || svc_tbl_name || ' where uid = ' || sub_id ;
for svc_data_rec in execute sql_str1 loop
end loop;
-- get service_user table's column names
for col_name in select column_name
from information_schema.columns
where table_name~svc_tbl_name loop
raise notice 'Column name:%', col_name.column_name;
raise notice 'Value: %', svc_data_rec[col_name.column_name];
end loop;
Thank you,
Mustafa ...
Adrian Klaver <aklaver@comcast.net> wrote:On Thursday 23 November 2006 10:54 pm, Mulham freshcode wrote:
> Hi Tom,
>
> Thanks for the help. Am using version 8.0 and it seems like RECORD is not
> that dynamic still. I tried with the FOR ... IN EXECUTE ... LOOP and it
> does the trick. But am still finding it hard to move forward with this. I
> have the name of table field in a varchar variable that i got from
> information_schema.columns and I have the records variable that stores the
> contains the data from that table. Usually I'd do something like
> data_rec.col_name to extract the data from the record but now I don't know
> the name per se. how can i say something like data_rec[col_name] where
> col_name is a variable that has the actual column name. I found no examples
> in the docs that explain this. Can it be done in version 8.0.1?
>
> I find variable substitution kind of confusing. I mean why is there no way
> of saying explicitly replace this variable with its content before
> executing the statement?
>
> Sorry for the long question,
> and thanks again for the help
>
> Mustafa...
>
> Tom Lane wrote: Mulham freshcode writes:
> > execute sql_str1 into svc_data_rec ;
> >
> > svc_data_rec is a RECORD, which is supposed to be dynamic.
>
> This should work --- in PG 8.1 or later. In older versions you'd have
> to fool around with a FOR ... IN EXECUTE ... loop.
>
> regards, tom lane
>
I am trying to sort this out. Are you trying to find the data for a single
field from each table, or for some set of fields?. If you are looking for
data from a single field couldn't you dispense with the RECORD variable and
just build a query of the form SELECT col_name FROM tbl_name. If you want to
go through a set of fields then it would involve some nested loops.
--
Adrian Klaver
aklaver@comcast.net
Access over 1 million songs - Yahoo! Music Unlimited.
Re: select into
От:
Adrian Klaver <aklaver@comcast.net>
Дата:
On Friday 24 November 2006 08:17 pm, Mulham freshcode wrote: > Hi Adrian, > > I have number of similar tables that have different number of fields > (similar in functionality). An in my stored procedure am trying to select a > row from one of these tables (that i don't know in advance, hence the use > of record) and return the data in the form of a table that has > column_name:value pairs. where column name is that from the original table. > I have no problem finding the column names but I don't know how to say > data[column_name] to get the corresponding value. Is there a way to do it > in pgsql? > > here is my code so far > > sql_str1 = 'select * from ' || svc_tbl_name || ' where uid = ' || > sub_id ; > > for svc_data_rec in execute sql_str1 loop > end loop; > > -- get service_user table's column names > for col_name in select column_name > from information_schema.columns > where table_name~svc_tbl_name loop > > raise notice 'Column name:%', col_name.column_name; > raise notice 'Value: %', svc_data_rec[col_name.column_name]; > > end loop; > > Thank you, > > Mustafa ... > I am afraid I can't make it work either. -- Adrian Klaver aklaver@comcast.net
Re: select into
От:
Adrian Klaver <aklaver@comcast.net>
Дата:
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
Re: select into
От:
Mulham freshcode <mulhamcode@yahoo.com>
Дата:
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.
Re: select into
От:
Adrian Klaver <aklaver@comcast.net>
Дата:
On Monday 27 November 2006 06:31 pm, Mulham freshcode wrote: > 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... > It may not be a shortcoming of the language, but a shortcoming in how well I understand it. I haven't given up hope I can make it work in plpgsql. The problem was I was going in circles. -- Adrian Klaver aklaver@comcast.net