pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Subqueryes
4+ messages / 3 participants
[nested] [flat]

* Subqueryes
@ 2007-03-22 13:48  Ezequias R. da Rocha <ezequias@fastcon.com.br>
  0 siblings, 2 replies; 4+ messages in thread

From: Ezequias R. da Rocha @ 2007-03-22 13:48 UTC (permalink / raw)
  To: pgsql-sql

Hi list,

I must add some days (i.e:365) to my current_date and put it in my table 
(an UPDATE). By now, it is simple but my "days to add" is in another table.

How could I do this kind of update

My sql is like this (but is not working):

update myTable
set date = (current_date + (Select daysToAdd from base.Table1 where 
myFKey_id = Table1Id) )
where Expire_Date = now()::Date;


-- 
Atenciosamente
Ezequias Rodrigues da Rocha




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Subqueryes
@ 2007-03-22 13:56  Alvaro Herrera <alvherre@commandprompt.com>
  parent: Ezequias R. da Rocha <ezequias@fastcon.com.br>
  1 sibling, 0 replies; 4+ messages in thread

From: Alvaro Herrera @ 2007-03-22 13:56 UTC (permalink / raw)
  To: Ezequias R. da Rocha <ezequias@fastcon.com.br>; +Cc: pgsql-sql

Ezequias R. da Rocha wrote:
> Hi list,
> 
> I must add some days (i.e:365) to my current_date and put it in my table 
> (an UPDATE). By now, it is simple but my "days to add" is in another table.
> 
> How could I do this kind of update
> 
> My sql is like this (but is not working):
> 
> update myTable
> set date = (current_date + (Select daysToAdd from base.Table1 where 
> myFKey_id = Table1Id) )
> where Expire_Date = now()::Date;

So what is the error message?

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Subqueryes
@ 2007-03-22 14:07  Richard Broersma Jr <rabroersma@yahoo.com>
  parent: Ezequias R. da Rocha <ezequias@fastcon.com.br>
  1 sibling, 1 reply; 4+ messages in thread

From: Richard Broersma Jr @ 2007-03-22 14:07 UTC (permalink / raw)
  To: Ezequias R. da Rocha <ezequias@fastcon.com.br>; pgsql-sql

> 
> update myTable
> set date = (current_date + (Select daysToAdd from base.Table1 where 
> myFKey_id = Table1Id) )
> where Expire_Date = now()::Date;

Does this work: http://www.postgresql.org/docs/8.2/interactive/sql-update.html

UPDATE myTable
SET date = current_date + B.daysToAdd
FROM Table1 B
WHERE myFKey_id = B.Table1Id;

Regards,
Richard Broersma Jr.




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Subqueryes
@ 2007-03-22 14:42  Ezequias R. da Rocha <ezequias@fastcon.com.br>
  parent: Richard Broersma Jr <rabroersma@yahoo.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Ezequias R. da Rocha @ 2007-03-22 14:42 UTC (permalink / raw)
  To: Richard Broersma Jr <rabroersma@yahoo.com>; +Cc: pgsql-sql

Perfect quite nice. I am doing things that I could not believe I could 
do without the community.

Thank you so much.

-- 
Atenciosamente
Ezequias Rodrigues da Rocha



Richard Broersma Jr escreveu:
>> update myTable
>> set date = (current_date + (Select daysToAdd from base.Table1 where 
>> myFKey_id = Table1Id) )
>> where Expire_Date = now()::Date;
>>     
>
> Does this work: http://www.postgresql.org/docs/8.2/interactive/sql-update.html
>
> UPDATE myTable
> SET date = current_date + B.daysToAdd
> FROM Table1 B
> WHERE myFKey_id = B.Table1Id;
>
> Regards,
> Richard Broersma Jr.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>
>   





^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2007-03-22 14:42 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-03-22 13:48 Subqueryes Ezequias R. da Rocha <ezequias@fastcon.com.br>
2007-03-22 13:56 ` Alvaro Herrera <alvherre@commandprompt.com>
2007-03-22 14:07 ` Richard Broersma Jr <rabroersma@yahoo.com>
2007-03-22 14:42   ` Ezequias R. da Rocha <ezequias@fastcon.com.br>

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