Re: [SQL] update column based on postgis query on anther table

2013-07-17 Thread Gulcin Yildirim
Sent from my iPhone İ On 16 Tem 2013, îat 08:24, Tom Lane wrote: > Stefan Sylla writes: >> Now I want to use a trigger function to automatically update the column >> 'id_test1_poly' in tabel 'test1_point': > >> /**/ >> create or replace function test1_point_get_id_test1_poly() returns >> tr

Re: [SQL] update column based on postgis query on anther table

2013-07-16 Thread Igor Neyman
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of ssylla > Sent: Tuesday, July 16, 2013 3:58 AM > To: pgsql-sql@postgresql.org > Subject: Re: [SQL] update column based on postgis query on anther table &

Re: [SQL] update column based on postgis query on anther table

2013-07-16 Thread ssylla
Hi Tom, I tried changing the trigger to be BEFORE instead of AFTER: create trigger test1_point_get_id_test1_poly before insert or update on test1_point for each row execute procedure test1_point_get_id_test1_poly(); But the problem persits, the column id_test1_poly remains empty. Stefan --

Re: [SQL] update column based on postgis query on anther table

2013-07-15 Thread Tom Lane
Stefan Sylla writes: > Now I want to use a trigger function to automatically update the column > 'id_test1_poly' in tabel 'test1_point': > /**/ > create or replace function test1_point_get_id_test1_poly() returns > trigger as $$ > begin > new.id_test1_poly=test1_point_get_id_test1

[SQL] update column based on postgis query on anther table

2013-07-15 Thread Stefan Sylla
Dear list, This might be a postgis-specific question, but I could not get access to the postgis mailing list so I will have a try here as my problem might be related to SQL: I need to update a column of a table based on a postgis-query function that involves another table as follows: Assum

Re: [SQL] Update a composite nested type variable

2013-07-08 Thread David Johnston
Luca Vernini wrote > 2013/7/8 David Johnston < > polobo@ > > > >> >> This may be a pl/pgsql limitation but you should probably provide a >> complete >> self-contained example with your attempt so that user-error can be >> eliminated. >> >> David J. >> >> > All right. Here you are a complete exam

Re: [SQL] Update a composite nested type variable

2013-07-08 Thread Luca Vernini
2013/7/8 David Johnston > > This may be a pl/pgsql limitation but you should probably provide a > complete > self-contained example with your attempt so that user-error can be > eliminated. > > David J. > > All right. Here you are a complete example. Just tested it. Sorry for the long email. CR

Re: [SQL] Update a composite nested type variable

2013-07-08 Thread David Johnston
Luca Vernini wrote > I'm writing a system with havy use of composite types. > I have a doubt. > > I'm writing all in functions with language plpgsql. > When I read a field from a composite type I must write something like > this: > status = ((in_customer.customer_data).customer_status).status_id >

[SQL] Update a composite nested type variable

2013-07-08 Thread Luca Vernini
I'm writing a system with havy use of composite types. I have a doubt. I'm writing all in functions with language plpgsql. When I read a field from a composite type I must write something like this: status = ((in_customer.customer_data).customer_status).status_id And this works fine. I need to en

Re: [SQL] UPDATE query with variable number of OR conditions in WHERE

2013-03-14 Thread Tom Lane
Ben Morrow writes: > Quoth jorgemal1...@gmail.com (JORGE MALDONADO): >> I am building an UPDATE query at run-time and one of the fields I want to >> include in the WHERE condition may repeat several times, I do not know how >> many. >> >> UPDATE table1 >> SET field1 = "some value" >> WHERE (field

Re: [SQL] UPDATE query with variable number of OR conditions in WHERE

2013-03-14 Thread Ben Morrow
Quoth jorgemal1...@gmail.com (JORGE MALDONADO): > > I am building an UPDATE query at run-time and one of the fields I want to > include in the WHERE condition may repeat several times, I do not know how > many. > > UPDATE table1 > SET field1 = "some value" > WHERE (field2 = value_1 OR field2 = va

[SQL] UPDATE query with variable number of OR conditions in WHERE

2013-03-14 Thread JORGE MALDONADO
I am building an UPDATE query at run-time and one of the fields I want to include in the WHERE condition may repeat several times, I do not know how many. UPDATE table1 SET field1 = "some value" WHERE (field2 = value_1 OR field2 = value_2 OR .OR field2 = value_n) I build such a query using a

Re: [SQL] Update HSTORE record and then delete if it is now empty - What is the correct sql?

2013-02-23 Thread Ashwin Jayaprakash
Thanks Tom. I'll try it out soon.

Re: [SQL] Update HSTORE record and then delete if it is now empty - What is the correct sql?

2013-02-23 Thread Ashwin Jayaprakash
Thanks, that makes sense. On Fri, Feb 22, 2013 at 9:53 PM, Ian Lawrence Barwick wrote: > 2013/2/23 Ashwin Jayaprakash : > (...) > > > > Q2: What the best way to check if an HSTORE is empty? Is this it > > "array_length(akeys(data), 1) is null"? > > Just a quick answer to your second question: I

Re: [SQL] Update HSTORE record and then delete if it is now empty - What is the correct sql?

2013-02-23 Thread Tom Lane
Ashwin Jayaprakash writes: > Hi, here's what I'm trying to do: >- I have a table that has an HSTORE column >- I would like to delete some key-vals from it >- If after deleting key-vals, the HSTORE column is empty, I'd like to > delete the entire row > with update_qry as( > update up

Re: [SQL] Update HSTORE record and then delete if it is now empty - What is the correct sql?

2013-02-22 Thread Ian Lawrence Barwick
2013/2/23 Ashwin Jayaprakash : (...) > > Q2: What the best way to check if an HSTORE is empty? Is this it > "array_length(akeys(data), 1) is null"? Just a quick answer to your second question: I suspect it might be more efficient to check your HSTORE column against an empty HSTORE, e.g. WHERE v

[SQL] Update HSTORE record and then delete if it is now empty - What is the correct sql?

2013-02-22 Thread Ashwin Jayaprakash
Hi, here's what I'm trying to do: - I have a table that has an HSTORE column - I would like to delete some key-vals from it - If after deleting key-vals, the HSTORE column is empty, I'd like to delete the entire row I have the sample SQL here and the DML I was trying out. I thought a CTE

Re: [SQL] Reuse temporary calculation results in an SQL update query

2012-10-01 Thread Thomas Kellerer
Matthias Nagel wrote on 29.09.2012 12:49: Hello, is there any way how one can store the result of a time-consuming calculation if this result is needed more than once in an SQL update query? This solution might be PostgreSQL specific and not standard SQL compliant. Here is an example of what

Re: [SQL] Reuse temporary calculation results in an SQL update query

2012-10-01 Thread Jasen Betts
On 2012-09-29, Matthias Nagel wrote: > Hello, > > is there any way how one can store the result of a time-consuming calculation > if this result is needed more than once in an SQL update query? This solution > might be PostgreSQL specific and not standard SQL compliant. Here is a

Re: [SQL] Reuse temporary calculation results in an SQL update query [SOLVDED]

2012-09-30 Thread David Johnston
> > thank you. The "WITH" clause did the trick. I did not even know that such a > thing exists. But as it turns out it makes the statement more readable and > elegant but not faster. > > The reason for the latter is that both the CTE and the UPDATE statement > have the same "FROM ... WHERE ..." p

Re: [SQL] Reuse temporary calculation results in an SQL update query [SOLVDED]

2012-09-29 Thread Matthias Nagel
schrieben: > > Matthias Nagel wrote on 29.09.2012 12:49: > > > Hello, > > > > > > is there any way how one can store the result of a time-consuming > > > calculation if this result is needed more > > >than once in an SQL update query? This

Re: [SQL] Reuse temporary calculation results in an SQL update query

2012-09-29 Thread Andreas Kretschmer
Thomas Kellerer hat am 29. September 2012 um 16:13 geschrieben: > Matthias Nagel wrote on 29.09.2012 12:49: > > Hello, > > > > is there any way how one can store the result of a time-consuming > > calculation if this result is needed more > >than once in an SQL

Re: [SQL] Reuse temporary calculation results in an SQL update query

2012-09-29 Thread Thomas Kellerer
Matthias Nagel wrote on 29.09.2012 12:49: Hello, is there any way how one can store the result of a time-consuming calculation if this result is needed more than once in an SQL update query? This solution might be PostgreSQL specific and not standard SQL compliant. Here is an example of what

Re: [SQL] Reuse temporary calculation results in an SQL update query

2012-09-29 Thread David Johnston
On Sep 29, 2012, at 6:49, Matthias Nagel wrote: > Hello, > > is there any way how one can store the result of a time-consuming calculation > if this result is needed more than once in an SQL update query? This solution > might be PostgreSQL specific and not standard SQL compli

Re: [SQL] Reuse temporary calculation results in an SQL update query

2012-09-29 Thread Matthias Nagel
Hello, > Matthias Nagel hat am 29. September 2012 um 12:49 > geschrieben: > > Hello, > > > > is there any way how one can store the result of a time-consuming > > calculation > > if this result is needed more than once in an SQL update query? This > >

Re: [SQL] Reuse temporary calculation results in an SQL update query

2012-09-29 Thread Andreas Kretschmer
Matthias Nagel hat am 29. September 2012 um 12:49 geschrieben: > Hello, > > is there any way how one can store the result of a time-consuming calculation > if this result is needed more than once in an SQL update query? This solution > might be PostgreSQL specific and not standar

[SQL] Reuse temporary calculation results in an SQL update query

2012-09-29 Thread Matthias Nagel
Hello, is there any way how one can store the result of a time-consuming calculation if this result is needed more than once in an SQL update query? This solution might be PostgreSQL specific and not standard SQL compliant. Here is an example of what I want: UPDATE table1 SET StartTime

Re: [SQL] UPDATE Multiple Records At Once?

2012-04-16 Thread lewbloch
Carlos Mennens wrote: > I'm trying to update a customer record in a table however I need to > change several values (cust_address, cust_contact, cust_email). My > question is how do I properly format this into one single command? > > > forza=# SELECT cust_id, cust_name, cust_address, cust_contact

Re: [SQL] UPDATE Multiple Records At Once?

2012-04-11 Thread Thomas Kellerer
ick example so I can see how this is drawn out via ANSI SQL? UPDATE customers SET cust_address = 'foo', cust_contact = 'Arthur', cust_email = 'art...@foo.bar' WHERE cust_name = 'iamUNIX' -- Sent via pgsql-sql mailing list (pgsql-sq

[SQL] UPDATE Multiple Records At Once?

2012-04-11 Thread Carlos Mennens
I'm trying to update a customer record in a table however I need to change several values (cust_address, cust_contact, cust_email). My question is how do I properly format this into one single command? forza=# SELECT cust_id, cust_name, cust_address, cust_contact, cust_email forza-# FROM customer

Re: [SQL] update column with multiple values

2012-02-10 Thread David Johnston
-Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of ssylla Sent: Wednesday, February 08, 2012 9:31 PM To: pgsql-sql@postgresql.org Subject: [SQL] update column with multiple values Dear list, sorry, I already posted this, but it

Re: [SQL] update column

2012-02-10 Thread Oliveiros d'Azevedo Cristina
UPDATE admin SET parent = SUBSTR(id,1,4); Doesn't it do what you want? Best, Oliveiros - Original Message - From: "ssylla" To: Sent: Thursday, February 09, 2012 1:58 AM Subject: [SQL] update column Dear list, sorry, I already posted this, but it did not se

[SQL] update column with multiple values

2012-02-10 Thread ssylla
Dear list, sorry, I already posted this, but it did not seem to have been accepted by the mailing list. So here's my second try: I need to update all rows of a column ('parent') based on a subquery that returns me the first four digits of another column ('id'): UPDATE admin SET parent=(SELECT SU

[SQL] update column

2012-02-10 Thread ssylla
Dear list, sorry, I already posted this, but it did not seem to have been accepted by the mailing list. So here's my second try: I need to update all rows of a column ('parent') based on a subquery that returns me the first four digits of another column ('id'): UPDATE admin SET parent=(SELECT SU

[SQL] update multiple columns with multiple values

2012-02-10 Thread ssylla
Dear list, I am trying to update all rows of a column ('parent') based on a subquery that returns me the first four digits of another column ('id'): After executing, I get the following error-message: I am not quite sure about that, but maybe I need to construct a function to fulfill this ta

Re: [SQL] Update Mass Data in Field?

2012-01-26 Thread David Johnston
-Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Carlos Mennens Sent: Thursday, January 26, 2012 6:59 PM To: PostgreSQL (SQL) Subject: [SQL] Update Mass Data in Field? I'm new to SQL so I'm looking for a way to chan

Re: [SQL] Update Mass Data in Field?

2012-01-26 Thread Steve Crawford
On 01/26/2012 03:59 PM, Carlos Mennens wrote: I'm new to SQL so I'm looking for a way to change several email addresses with one command. For example everyone has a 'holyghost.org' domain and I need to change a few 100 email addresses in the field 'emp_email'. I need to UPDATE employees table whi

[SQL] Update Mass Data in Field?

2012-01-26 Thread Carlos Mennens
I'm new to SQL so I'm looking for a way to change several email addresses with one command. For example everyone has a 'holyghost.org' domain and I need to change a few 100 email addresses in the field 'emp_email'. I need to UPDATE employees table which has a COLUMN 'emp_email' and change %holyghos

Re: [SQL] UPDATE COMPATIBILITY

2012-01-17 Thread Samuel Gendler
On Tue, Jan 17, 2012 at 12:49 AM, Thomas Kellerer wrote: > Gera Mel Handumon, 17.01.2012 07:31: > > What version of postgresql that the update compatibility below will be >> implemented? >> >> UPDATE COMPATIBILITY >> >> >> UPDATE accounts SET (contact_last_name, contact_first_name) = >> (SELE

Re: [SQL] UPDATE COMPATIBILITY

2012-01-17 Thread Thomas Kellerer
Adrian Klaver, 17.01.2012 16:19: You need to rewrite it to: UPDATE accounts SET contact_last_name = s.last_name, contact_first_name = s.first_name FROM salesmen s WHERE s.id = accounts.sales_id For completeness, you could also do: UPDATE accounts SET (contact_last_name,cont

Re: [SQL] UPDATE COMPATIBILITY

2012-01-17 Thread Adrian Klaver
On Tuesday, January 17, 2012 12:49:44 am Thomas Kellerer wrote: > Gera Mel Handumon, 17.01.2012 07:31: > > None as far as I know. > > You need to rewrite it to: > > UPDATE accounts >SET contact_last_name = s.last_name, >contact_first_name = s.first_name > FROM salesmen s > WHERE s.i

Re: [SQL] UPDATE COMPATIBILITY

2012-01-17 Thread Thomas Kellerer
Gera Mel Handumon, 17.01.2012 07:31: What version of postgresql that the update compatibility below will be implemented? UPDATE COMPATIBILITY UPDATE accounts SET (contact_last_name, contact_first_name) = (SELECT last_name, first_name FROM salesmen WHERE salesmen.id = accounts.sales_

[SQL] UPDATE COMPATIBILITY

2012-01-16 Thread Gera Mel Handumon
What version of postgresql that the update compatibility below will be implemented? UPDATE COMPATIBILITY UPDATE accounts SET (contact_last_name, contact_first_name) = (SELECT last_name, first_name FROM salesmen WHERE salesmen.id = accounts.sales_id); TIA, -- Gera Mel E. Handumon --

Re: [SQL] update with recursive query

2011-04-14 Thread Pavel Stehule
Hello it is possible in 9.1. In older version you have to use a temp table. Regards Pavel Stehule 2011/4/14 Steven Dahlin : > Is it possible to execute an update using recursion?  I need to update a set > of records and also update their children with the same value.  I tried the > following qu

[SQL] update with recursive query

2011-04-14 Thread Steven Dahlin
Is it possible to execute an update using recursion? I need to update a set of records and also update their children with the same value. I tried the following query but it gave an error at the "update schema.table tbl": with recursive childTbl( pid, ppid,

[SQL] update using recursion

2011-04-14 Thread Steven Dahlin
Is it possible to execute an update using recursion?  I need to update a set of records and also update their children with the same value. I tried the following query but it gave an error at the "update schema.table tbl":     with recursive childTbl( pid, ppid,   

Re: [SQL] UPDATE in a specific order

2010-12-17 Thread Luiz K. Matsumura
Thanks for reply, Em 16/12/2010 17:58, Jasen Betts escreveu: I need to make update of table1 with data on table2 in the order of id of table2 that looks like EAV. is it? Err, I don´t know so much about EAV, so I think that isn´t. I´m just trying to reproduce a calc in a spreeadsheet. Ther

Re: [SQL] UPDATE in a specific order

2010-12-16 Thread Jasen Betts
> I need to make update of table1 with data on table2 in the order of id > of table2 that looks like EAV. is it? > I=B4m trying to do an update like this: that's not going to work. perhaps you can rewrite the from part to only return one row for every table1_fk, this one row will combine seve

[SQL] UPDATE in a specific order

2010-12-16 Thread Luiz K. Matsumura
Hi, I have a follow scenario: CREATE TABLE table1 ( id integer , vlpr numeric(10,2) , vlab numeric(10,2) , vlbx numeric(15,5) , pct numeric(12,8) ); CREATE TABLE table2 ( id integer , fk_table1 integer , tpop char(2) , valor numeric(15,5) ); insert into table1 VALUES ( 1, 200 , 0 , 0

Re: [SQL] update from join

2009-05-14 Thread Rob Sargent
I wonder if this works: update stock s set s_superceded = true where s.s_updated < (select max(t.s_updated) from stock t where t.s_vin = s.s_vin) On Thu, May 14, 2009 at 7:27 AM, Gary Stainburn < gary.stainb...@ringways.co.uk> wrote: > I know I should be able to do this but my brain's mashed

[SQL] update from join

2009-05-14 Thread Gary Stainburn
I know I should be able to do this but my brain's mashed today I have a stock table with s_stock_no varchar primary key s_vin varchar s_updated timestamp s_supercededboolean It is possible for the same vin to exist on stock if we have s

Re: [SQL] UPDATE and DELEte with a lot of register is to slow...

2008-11-28 Thread John Dizaro
O Problema é tem tenho uma tabela muito grande com chave primaria e tudo mais... e quando eu vou fazer uma atualização de alguns campos desta tabela o banco fica devagar estou procurando algum comando que me permita atualizar os registros aos poucos por exemplo uma tabela com 100 000 atualiza-l

Re: [SQL] UPDATE and DELEte with a lot of register is to slow...

2008-11-21 Thread John Dizaro
The problem is ... how to run the SCRIPT to the few? not all the 5 lines of "update" at the same time. John Evan Dizaro 2008/11/20 John Dizaro <[EMAIL PROTECTED]> > I have to execute some times an UPDATE an some times a DELETE to > register +- 5 , every time when i do that the dat

Res: [SQL] UPDATE and DELEte with a lot of register is to slow...

2008-11-20 Thread paulo matadr
did you make analyse(vacuum ) in you database? De: Craig Ringer <[EMAIL PROTECTED]> Para: John Dizaro <[EMAIL PROTECTED]> Cc: pgsql-sql@postgresql.org Enviadas: Quinta-feira, 20 de Novembro de 2008 8:29:55 Assunto: Re: [SQL] UPDATE and DELEte w

Re: [SQL] UPDATE and DELEte with a lot of register is to slow...

2008-11-20 Thread Craig Ringer
John Dizaro wrote: I have to execute some times an UPDATE an some times a DELETE to register +- 5 , every time when i do that the database be to slow do we any way to DELETE or UPDATE by part??? I'm not sure your post really contains enough information to answer your question. If

[SQL] UPDATE and DELEte with a lot of register is to slow...

2008-11-20 Thread John Dizaro
I have to execute some times an UPDATE an some times a DELETE to register +- 5 , every time when i do that the database be to slow do we any way to DELETE or UPDATE by part??? Thanks -- John Evan Dizaro -

Re: [SQL] Update and trigger

2008-06-11 Thread A. Kretschmer
am Wed, dem 11.06.2008, um 0:54:55 -0700 mailte Medi Montaseri folgendes: > Thanks...but a difference seems to be that the rule is not specific to update > on a particular col but any col of a row getting updated... > > Thanks Okay, but i havn't an idea. A statement level trigger can't see the

Re: [SQL] Update and trigger

2008-06-11 Thread Medi Montaseri
Thanks...but a difference seems to be that the rule is not specific to update on a particular col but any col of a row getting updated... Thanks On Tue, Jun 10, 2008 at 10:21 PM, A. Kretschmer < [EMAIL PROTECTED]> wrote: > am Tue, dem 10.06.2008, um 18:45:51 -0700 mailte Medi Montaseri folgende

Re: [SQL] Update and trigger

2008-06-10 Thread Craig Ringer
Medi Montaseri wrote: Hi, I need to increament a counter such as myTable.Counter of type integer everytime myTable.status a boolean column is updated. Can you help me complete this... create trigger counter_trigger after update on myTable.counter execute procedure 'BEGIN statement; statement

Re: [SQL] Update and trigger

2008-06-10 Thread A. Kretschmer
am Tue, dem 10.06.2008, um 18:45:51 -0700 mailte Medi Montaseri folgendes: > Hi, > > I need to increament a counter such as myTable.Counter of type integer > everytime myTable.status a boolean column is updated. Can you help me complete > this... > > create trigger counter_trigger after update o

[SQL] Update and trigger

2008-06-10 Thread Medi Montaseri
Hi, I need to increament a counter such as myTable.Counter of type integer everytime myTable.status a boolean column is updated. Can you help me complete this... create trigger counter_trigger after update on myTable.counter execute procedure 'BEGIN statement; statement; statement END' Q1- how d

Re: [SQL] Update problem

2008-06-03 Thread samantha mahindrakar
Iam sorry for the previous mail..it was in complete. Please do not consider it. I think i could figure out the problem for the updates not happening. Following is the function that does the update : BEGIN IF flag=1 THEN tempQuery:='UPDATE '||thepartition||' SET volume='||update

Re: [SQL] Update problem

2008-06-03 Thread samantha mahindrakar
I tried getting the output of the execute statements by printing the FOUND variable. It is returning the value as false. However i used PEFORM instead of EXECUTE for the update statement. It On 6/3/08, samantha mahindrakar <[EMAIL PROTECTED]> wrote: > Hi > Iam facing a strange issue > One

[SQL] Update problem

2008-06-03 Thread samantha mahindrakar
Hi Iam facing a strange issue One of the functions in my program is running an update statement. The statement is running cross-schema. What i mean is that the program resides in one schema where as it updates a table from another schema. How ever these scehmas are on the same database. The

[SQL] UPDATE with table join

2008-05-27 Thread Tarlika Elisabeth Schmitz
I need to update some records in a table depending on values in another table: UPDATE item SET export_time = now() WHERE item_pk IN ( SELECT item.item_pk AS pk FROM ITEM LEFT JOIN product product ON Item.product_fk = product.product_pk WHERE product.xyz = 't' AND ... ) Is this the most

Re: [SQL] update with multiple fields as aggregates

2008-05-03 Thread Volkan YAZICI
On Sat, 3 May 2008, Alexy Khrabrov <[EMAIL PROTECTED]> writes: > I need to fill two columns of a Rats table from an Offset1 table, > where for each Id row in Rats we need to fill an average offset and > the sum of all offset from Offset1 with the same Id. I can create a > derivative table like thi

[SQL] update with multiple fields as aggregates

2008-05-03 Thread Alexy Khrabrov
I need to fill two columns of a Rats table from an Offset1 table, where for each Id row in Rats we need to fill an average offset and the sum of all offset from Offset1 with the same Id. I can create a derivative table like this: create table ofrats as (select customer_id as cid,avg(o),sum

Re: [SQL] update with join

2008-04-03 Thread Ivan Sergio Borgonovo
On Wed, 2 Apr 2008 23:54:18 -0300 "Osvaldo Kussama" <[EMAIL PROTECTED]> wrote: > 2008/4/2, Ivan Sergio Borgonovo <[EMAIL PROTECTED]>: > > I've > > > > create table types( > > typeid int, > > special boolean not null > > ); > > > > create table methods( > > methodid int, > > typeid refer

Re: [SQL] update with join

2008-04-02 Thread Osvaldo Kussama
2008/4/2, Ivan Sergio Borgonovo <[EMAIL PROTECTED]>: > I've > > create table types( > typeid int, > special boolean not null > ); > > create table methods( > methodid int, > typeid references types(typeid), > ); > > create table orders( > orderid int > ); > > create table order_pay

[SQL] update with join

2008-04-02 Thread Ivan Sergio Borgonovo
I've create table types( typeid int, special boolean not null ); create table methods( methodid int, typeid references types(typeid), ); create table orders( orderid int ); create table order_payments( payid int orderid references order(orderid), methodid references method(metho

Re: [SQL] UPDATE .. FROM

2008-03-07 Thread Tom Lane
"Markus Bertheau" <[EMAIL PROTECTED]> writes: > I'm kind of stuck as to why postgresql doesn't understand what I mean in the > following queries: > UPDATE tag_data td SET td.usage_counter = td.usage_counter + 1 FROM > tag_list_tag_data ltd WHERE ltd.tag_id = td.id AND ltd.id = 102483; > ERROR: c

[SQL] UPDATE .. FROM

2008-03-07 Thread Markus Bertheau
I'm kind of stuck as to why postgresql doesn't understand what I mean in the following queries: UPDATE tag_data td SET td.usage_counter = td.usage_counter + 1 FROM tag_list_tag_data ltd WHERE ltd.tag_id = td.id AND ltd.id = 102483; ERROR: column "td" of relation "tag_data" does not exist LINE 1:

[SQL] UPDATE with ORDER BY

2008-02-19 Thread Robins Tharakan
Hi, I know this kind of a question is asked earlier, but I couldn't find an answer there (in the previous round of posting). Instead of wanting to update the first record in an UPDATE .. ORDER BY condition, (because of triggers that act downward) what I want is that all records be updated, but in

Re: [SQL] Update PK Violation

2008-01-16 Thread Franklin Haut
Scott Marlowe wrote: On Jan 15, 2008 3:03 PM, Franklin Haut <[EMAIL PROTECTED]> wrote: Hi all, i have a problem with one update sentence sql. example to produce: create table temp (num integer primary key, name varchar(20)); insert into temp values (1, 'THE'); insert into temp

Re: [SQL] Update PK Violation

2008-01-16 Thread Scott Marlowe
On Jan 16, 2008 8:30 AM, Achilleas Mantzios <[EMAIL PROTECTED]> wrote: > Στις Tuesday 15 January 2008 23:03:49 ο/η Franklin Haut έγραψε: > > Hi all, > > > > i have a problem with one update sentence sql. > > > > A simple way i use: > > foodb=# update temp set num = num*1000 where num >= 5; > foodb

Re: [SQL] Update PK Violation

2008-01-16 Thread Achilleas Mantzios
Στις Tuesday 15 January 2008 23:03:49 ο/η Franklin Haut έγραψε: > Hi all, > > i have a problem with one update sentence sql. > A simple way i use: foodb=# update temp set num = num*1000 where num >= 5; foodb=# insert into temp values (5, 'NOT'); foodb=# update temp set num = 1 + num/1000 wher

Re: [SQL] Update PK Violation

2008-01-16 Thread Fernando Hevia
> Franklin Haut wrote: > > Hi all, > > i have a problem with one update sentence sql. > > example to produce: > > create table temp (num integer primary key, name varchar(20)); > > insert into temp values (1, 'THE'); > insert into temp values (2, 'BOOK'); > insert into temp values (3, 'IS');

Re: [SQL] Update PK Violation

2008-01-15 Thread Scott Marlowe
On Jan 15, 2008 3:03 PM, Franklin Haut <[EMAIL PROTECTED]> wrote: > Hi all, > > i have a problem with one update sentence sql. > > example to produce: > > create table temp (num integer primary key, name varchar(20)); > > insert into temp values (1, 'THE'); > insert into temp values (2, 'BOOK'); >

[SQL] Update PK Violation

2008-01-15 Thread Franklin Haut
Hi all, i have a problem with one update sentence sql. example to produce: create table temp (num integer primary key, name varchar(20)); insert into temp values (1, 'THE'); insert into temp values (2, 'BOOK'); insert into temp values (3, 'IS'); insert into temp values (4, 'ON'); insert into t

Re: [SQL] update on join ?

2007-11-21 Thread chester c young
> I tried > > UPDATE things JOIN inventory ON things.thing_id = inventory.thing_fk > SET number = 0 > WHERE color = 'red' > use the cool "from" clause in the update update things t set number = 0 from inventory i where t.thing_id = i.thing_fk and i.color = 'red'; _

Re: [SQL] update on join ?

2007-11-21 Thread Richard Broersma Jr
--- On Wed, 11/21/07, Andreas <[EMAIL PROTECTED]> wrote:> > UPDATE inventory > SET number = 0 > WHERE thing_fk IN (SELECT thing_id FROM things WHERE color > = 'red') This is a perfectly acceptable ANSI-SQL update statement. Here is non-ANSI update statement that

Re: [SQL] update on join ?

2007-11-21 Thread Frank Bax
Andreas wrote: I'd like to update a table efficiently where the relevant select-info is in another table that is foreign-linked. Stupid example. 2 tables: things (thing_id integer, name varchar(100), color varchar(100)) inventory (item_id integer, thing_fk integer references things (thing_id

[SQL] update on join ?

2007-11-21 Thread Andreas
Hi, I'd like to update a table efficiently where the relevant select-info is in another table that is foreign-linked. Stupid example. 2 tables: things (thing_id integer, name varchar(100), color varchar(100)) inventory (item_id integer, thing_fk integer references things (thing_id), number)

Re: [SQL] update from select

2007-10-29 Thread Tom Lane
<[EMAIL PROTECTED]> writes: > Hash Join (cost=10827.45..25950.05 rows=4906 width=1191) (actual > time=586.251..2852.691 rows=111306 loops=1) > ... > Total runtime: 633548.404 ms So you're worried about the wrong thing entirely. The query is taking less than 3 seconds, which may be reasonable con

Re: [SQL] update from select

2007-10-29 Thread Pavel Stehule
actual time=2.848..6.485 rows=6 loops=19489)" > "Index Cond: ((""owner"".asin)::text = (detail_dvd.asin)::text)" > Total runtime: 1039998.325 ms > *** > try to up statististics on table det

Re: [SQL] update from select

2007-10-29 Thread dev
tal runtime: 1039998.325 ms *** Thaks for helping!! Bye the way, we are changing our system from MSSQL2000 to Postgres :-)! Regards Reto -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von A. Kr

Re: [SQL] update from select

2007-10-29 Thread Tom Lane
<[EMAIL PROTECTED]> writes: > Is there a better way to do this update: > UPDATE table1 SET column2 = temp_table.column2, column3 = > temp_table.column3, column4 = CAST(temp_table.column4 AS date) FROM > ( > SELECT DISTINCT > table2.column1, > table2.column2, > table2.column3, > table2.column4

Re: [SQL] update from select

2007-10-29 Thread Pavel Stehule
Hello you use corelated subquery and that is slow for thausands rows. Use PostgreSQL's extension UPDATE table1 SET column2 = t,colum2, FROM table2 t WHERE table1.column1 = t.column1 and t.column4 is not null and ... http://www.postgresql.org/docs/8.2/interactive/sql-update.html Regards Pav

Re: [SQL] update from select

2007-10-29 Thread A. Kretschmer
am Mon, dem 29.10.2007, um 10:18:38 +0100 mailte [EMAIL PROTECTED] folgendes: > > WHERE table1.column1 = temp_table.column1; table1.column1 and temp_table.column1 have the same type? > > > > The select by it?s own takes around 1 second. The Update is around 120?000 > rows. I got an index on

[SQL] update from select

2007-10-29 Thread dev
Hello I have a performance problem with an SQL statement. Is there a better way to do this update: UPDATE table1 SET column2 = temp_table.column2, column3 = temp_table.column3, column4 = CAST(temp_table.column4 AS date) FROM ( SELECT DISTINCT table2.column1, table2.column2, table2

[SQL] update from and left join

2007-04-11 Thread Tomasz Myrta
Hello I have a query: update A set... from B left join C on (C.col1=B.col1 and C.col2=A.col2) where ... which gives me an error: ERROR: invalid reference to FROM-clause entry for table "A" HINT: There is an entry for table "A", but it cannot be referenced from this part of the query. I fo

[SQL] Update Field with function/data from other tables?

2007-04-06 Thread paallen
Hi all, I want to update the values of a column with the result of a function that requires information from another table. Specifically it needs a minium and maximum value from another table. How do I perform the update query? Below is my attempt but it doesn't work. The "bhlineid" is my prim

Re: [SQL] Update problem.

2007-04-03 Thread Andrew Sullivan
On Tue, Apr 03, 2007 at 09:13:00AM +0200, Shavonne Marietta Wijesinghe wrote: > Thanks. But to do the UPDATE i have to write each column name (for recrd 4) > and with its column name (for record 2) which is quite alot to write :P > > UPDATE MOD48_00_2007 SET te_cognome= te_cognome, te_paternita=

Re: [SQL] Update problem.

2007-04-03 Thread Shavonne Marietta Wijesinghe
column name = to the column name. And i have to do it for echt field? isn't there any other way.. "I hate writting :P" And Andrew can explain a bit the setval() Thanks Shavonne Wijesinghe From: "Andrew Sullivan" <[EMAIL PROTECTED]> To: Sent: Monday, April 02, 2007 5:

Re: [SQL] Update problem.

2007-04-02 Thread Andrew Sullivan
On Mon, Apr 02, 2007 at 04:52:46PM +0200, Shavonne Marietta Wijesinghe wrote: > At a surtain point i need to replace a record with another > > For example i have inserted 4 records. (1, 2 , 3 , 4) I need to > replace all the values from the record 4 to the record 2 but > keeping the n_gen serial

[SQL] Update problem.

2007-04-02 Thread Shavonne Marietta Wijesinghe
Hello I have a table created as the following CREATE TABLE mod48_00_2007 ( id text, n_gen serial NOT NULL, formstore text, te_cognome text, te_paternita text, te_nome text, te_sesso text, te_dtnasc text, te_attnasc text, te_luonasc text, te_provstato text, te_indi text,

[SQL] Update problem.

2007-04-02 Thread Shavonne Marietta Wijesinghe
Hello I have a table created as the following CREATE TABLE mod48_00_2007 ( id text, n_gen serial NOT NULL, formstore text, te_cognome text, te_paternita text, te_nome text, te_sesso text, te_dtnasc text, te_attnasc text, te_luonasc text, te_provstato text, te_indi text,

Re: [SQL] Update query by joining multiple tables.

2007-01-17 Thread Shoaib Mir
Might be a view and then a rule attached with that can help you out with doing updates using joins -- Shoaib Mir EnterpriseDB (www.enterprisedb.com) On 1/17/07, Andrew Sullivan <[EMAIL PROTECTED]> wrote: On Wed, Jan 17, 2007 at 04:50:18PM +0530, Moiz Kothari wrote: > http://www.pos

Re: [SQL] Update query by joining multiple tables.

2007-01-17 Thread Andrew Sullivan
On Wed, Jan 17, 2007 at 04:50:18PM +0530, Moiz Kothari wrote: > http://www.postgresql.org/docs/8.1/interactive/sql-update.html, it is not > specified if a join can be done between multiple tables to update a table, i Sure it is: A list of table expressions, allowing columns from other tables to a

[SQL] Update query by joining multiple tables.

2007-01-17 Thread Moiz Kothari
Guys, on page this http://www.postgresql.org/docs/8.1/interactive/sql-update.html, it is not specified if a join can be done between multiple tables to update a table, i tried and it worked just fine for me. Something like this : Infact update can work between multiple tables to... do something

  1   2   3   >