Re: [SQL] Select into

2008-03-20 Thread Erik Jones
On Mar 20, 2008, at 7:10 AM, Joe wrote: Gavin 'Beau' Baumanis wrote: The copy is inside the same table, so I don't understand why it (the required query ) would require any joins. Ie. I want to copy the contents of a row (but for the id column - of course) into a record in the same tabl

Re: [SQL] Select into

2008-03-20 Thread Gurjeet Singh
On Thu, Mar 20, 2008 at 7:08 PM, Joe <[EMAIL PROTECTED]> wrote: > Gurjeet Singh wrote: > > Except that it doesn't work... Did you try to execute that query; I am > > assuming not. > Of course I did, My bad... I did not run your query either, and based my assumption on my previous attempt that ha

Re: [SQL] Select into

2008-03-20 Thread Joe
Gurjeet Singh wrote: Except that it doesn't work... Did you try to execute that query; I am assuming not. Of course I did, do you think I create results by editing them into my email? The script: delete from t1; insert into t1 values (1, 123, 'first record'); insert into t1 values (2, 456, 's

Re: [SQL] Select into

2008-03-20 Thread Craig Ringer
Gurjeet Singh wrote: Except that it doesn't work... Did you try to execute that query; I am assuming not. It does, or at least a query written to work the same way works fine for me. Not only that, but at least in the presence of a unique index the query planner optimises it to the same quer

Re: [SQL] Select into

2008-03-20 Thread Gurjeet Singh
On Thu, Mar 20, 2008 at 5:40 PM, Joe <[EMAIL PROTECTED]> wrote: > Gavin 'Beau' Baumanis wrote: > > > > The copy is inside the same table, so I don't understand why it (the > > required query ) would require any joins. > > > > Ie. I want to copy the contents of a row (but for the id column - of > >

Re: [SQL] Select into

2008-03-20 Thread Joe
Gavin 'Beau' Baumanis wrote: The copy is inside the same table, so I don't understand why it (the required query ) would require any joins. Ie. I want to copy the contents of a row (but for the id column - of course) into a record in the same table. I think what you want is something like

Re: [SQL] Select into

2008-03-20 Thread Craig Ringer
craig=# update x set val = foundrow.val from ( select val from x where id = 2 ) as foundrow where id = 1 ; UPDATE 1 Thinking about it, it'd actually be better written as: UPDATE x SET val = foundrow.val FROM ( SELECT val FROM x AS x2 WHERE x2.id = 2 ) AS foundrow WHERE id = 1; ... be

Re: [SQL] Select into

2008-03-20 Thread Gavin 'Beau' Baumanis
Hi Everyone, I want to thank everyone for their help / suggestions... I really appreciate it. Though I think I have found a winner. craig=# update x set val = foundrow.val from ( select val from x where id = 2 ) as foundrow where id = 1 ; UPDATE 1 Very elegant, very clean... Very nice! T

Re: [SQL] Select into

2008-03-20 Thread Gurjeet Singh
On Thu, Mar 20, 2008 at 5:35 PM, Craig Ringer <[EMAIL PROTECTED]> wrote: > > craig=# explain update x set val = foundrow.val from ( select val from x > where id = 4123 ) as foundrow where id = 5912 ; > Thats nifty. -- [EMAIL PROTECTED] [EMAIL PROTECTED] gmail | hotmail | indiatimes | yahoo }.

Re: [SQL] Select into

2008-03-20 Thread Craig Ringer
Gavin 'Beau' Baumanis wrote: The copy is inside the same table, so I don't understand why it (the required query ) would require any joins. Maybe you should use FROM clause in the update that references a row-valued subquery? craig=# create table x ( id serial, val integer ); NOTICE: CREATE

Re: [SQL] Select into

2008-03-20 Thread Gurjeet Singh
On Thu, Mar 20, 2008 at 4:39 PM, Gavin 'Beau' Baumanis < [EMAIL PROTECTED]> wrote: > HI Gurjeet, > You're right. > > But what information do you need to know? > > The copy is inside the same table, so I don't understand why it (the > required query ) would require any joins. > > Ie. I want to copy

Re: [SQL] Select into

2008-03-20 Thread Greg Sabino Mullane
-BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 > Ie. I want to copy the contents of a row (but for the id > column - of course) into a record in the same table. BEGIN; CREATE TEMP TABLE tempfoo AS SELECT * FROM foo WHERE id = 123; UPDATE tempfoo SET id = 456; DELETE FROM foo WHERE id = 456;

Re: [SQL] Select into

2008-03-20 Thread Gavin 'Beau' Baumanis
HI Gurjeet, You're right. But what information do you need to know? The copy is inside the same table, so I don't understand why it (the required query ) would require any joins. Ie. I want to copy the contents of a row (but for the id column - of course) into a record in the same table.

Re: [SQL] Select into

2008-03-20 Thread Gurjeet Singh
On Thu, Mar 20, 2008 at 4:19 PM, A. Kretschmer < [EMAIL PROTECTED]> wrote: > am Thu, dem 20.03.2008, um 20:57:53 +1100 mailte Gavin 'Beau' Baumanis > folgendes: > > Hi Everyone, > > > > I have asked our DBA at work and h is not too sure either... so I > > thought it best to on the list. > > > > B

Re: [SQL] Select into

2008-03-20 Thread A. Kretschmer
am Thu, dem 20.03.2008, um 20:57:53 +1100 mailte Gavin 'Beau' Baumanis folgendes: > Hi Everyone, > > I have asked our DBA at work and h is not too sure either... so I > thought it best to on the list. > > Basically, what I am after is a way to copy the contents of one record > into another.

[SQL] Select into

2008-03-20 Thread Gavin 'Beau' Baumanis
Hi Everyone, I have asked our DBA at work and h is not too sure either... so I thought it best to on the list. Basically, what I am after is a way to copy the contents of one record into another. Something like select into; but where the destination record already exists, as opposed to cr

Re: [SQL] Select into with dynamic criteria in a plpgsql function

2007-10-28 Thread Paul Lambert
Paul Lambert wrote: I've got a function defined in PL/PgSQL to update some fields in a record where the criteria for pulling out some other values from a table is dynamic. I define a string called account_criteria to which I assign a normal SQL WHERE clause based on some work done earlier in

[SQL] Select into with dynamic criteria in a plpgsql function

2007-10-28 Thread Paul Lambert
I've got a function defined in PL/PgSQL to update some fields in a record where the criteria for pulling out some other values from a table is dynamic. I define a string called account_criteria to which I assign a normal SQL WHERE clause based on some work done earlier in the function. I then

Re: [SQL] select into

2006-11-27 Thread Adrian Klaver
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

Re: [SQL] select into

2006-11-27 Thread Mulham freshcode
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 ag

Re: [SQL] select into

2006-11-26 Thread Adrian Klaver
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 $Bo

Re: [SQL] select into

2006-11-26 Thread Adrian Klaver
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 us

Re: [SQL] select into

2006-11-24 Thread Mulham freshcode
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 c

Re: [SQL] select into

2006-11-24 Thread Tom Lane
Adrian Klaver <[EMAIL PROTECTED]> 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-STAT

Re: [SQL] select into

2006-11-24 Thread Adrian Klaver
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.

Re: [SQL] select into

2006-11-24 Thread Adrian Klaver
On Friday 24 November 2006 06:55 am, Andreas Kretschmer wrote: > Adrian Klaver <[EMAIL PROTECTED]> schrieb: > > On Thursday 23 November 2006 08:45 pm, Tom Lane wrote: > > > Mulham freshcode <[EMAIL PROTECTED]> writes: > > > > execute sql_str1 into svc_data_rec ; > > > > > > > > svc_data_rec is a RE

Re: [SQL] select into

2006-11-24 Thread Andreas Kretschmer
Adrian Klaver <[EMAIL PROTECTED]> schrieb: > On Thursday 23 November 2006 08:45 pm, Tom Lane wrote: > > Mulham freshcode <[EMAIL PROTECTED]> 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

Re: [SQL] select into

2006-11-24 Thread Adrian Klaver
On Thursday 23 November 2006 08:45 pm, Tom Lane wrote: > Mulham freshcode <[EMAIL PROTECTED]> 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 arou

Re: [SQL] select into

2006-11-23 Thread Mulham freshcode
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 fro

Re: [SQL] select into

2006-11-23 Thread Tom Lane
Mulham freshcode <[EMAIL PROTECTED]> 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. regar

Re: [SQL] select into

2006-11-23 Thread Mulham freshcode
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 usin

Re: [SQL] select into

2006-11-23 Thread Adrian Klaver
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 > pro

Re: [SQL] select into

2006-11-23 Thread Mulham freshcode
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

Re: [SQL] select into

2006-11-22 Thread Richard Broersma Jr
--- Andreas Kretschmer <[EMAIL PROTECTED]> wrote: > Richard, the plain SQL "INSERT INTO " is an other thing as the > original problem... > > He is in a PL/pgsql - function and he should rewrite this to use EXECUTE > ... INTO > I see, I am not even a novice yet when it comes PL/pgsql. Thanks f

Re: [SQL] select into

2006-11-22 Thread Tom Lane
Mulham freshcode <[EMAIL PROTECTED]> 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 >

Re: [SQL] select into

2006-11-22 Thread Andreas Kretschmer
Richard Broersma Jr <[EMAIL PROTECTED]> 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_

Re: [SQL] select into

2006-11-22 Thread Richard Broersma Jr
> 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

Re: [SQL] select into

2006-11-22 Thread A. Kretschmer
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

[SQL] select into

2006-11-22 Thread Mulham freshcode
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

[SQL] SELECT INTO returning more than one row

2005-06-27 Thread Zac
Hi. I have this problem in a plpgsql function: SELECT INTO myvar col FROM table WHERE ...; IF THEN do something ELSE IF THEN do something else ELSE do other things If I know that myvar IS NULL OR GET DIAGNOSTICS ROW_COUNT is zero. Is there a way to know if the que

Re: [SQL] 'Select INTO" in Execute (dynamic query )

2005-04-22 Thread Ramakrishnan Muralidharan
5 PMTo: pgsql-sql@postgresql.org; pgsql-general@postgresql.orgSubject: [SQL] 'Select INTO" in Execute (dynamic query ) Hi   What’s wrong with this code (ERROR:  syntax error at or near "INTO" at character 8)?   Problem: I want to put A1, A2 values i

[SQL] 'Select INTO" in Execute (dynamic query )

2005-04-18 Thread Dinesh Pandey
Hi   What’s wrong with this code (ERROR:  syntax error at or near "INTO" at character 8)?   Problem: I want to put A1, A2 values in two variables vara, varb.   CREATE OR REPLACE FUNCTION test(text) RETURNS VARCHAR AS $$ Declare   vara    VARCHAR(10) :='';   varb  

Re: [SQL] Select into

2004-01-12 Thread Richard Huxton
On Monday 12 January 2004 01:09, beyaRecords - The home Urban music wrote: > Hi, > I want to copy a sequence of rows from one table into another table. I > have tried select into but this will only work if the table you are > copying to does not already exist. How do I copy to a table that does > a

[SQL] Select into

2004-01-11 Thread beyaRecords - The home Urban music
Hi, I want to copy a sequence of rows from one table into another table. I have tried select into but this will only work if the table you are copying to does not already exist. How do I copy to a table that does already exist? regards Uzo ---(end of broadcast)

[SQL] SELECT * INTO TABLE is not working for me.

2001-05-30 Thread Roy Souther
I am testing my SQL commands in pgaccess before I put them into my C++ code. Trying to copy a table using... SELECT * INTO TABLE copy_stuff FROM the_stuff It creates the view but no table called copy_stuff exists after I run it. Why? I can use... CREATE TABLE copy_stuff AS SELECT * FROM the_stuff