Unix Technical Forum

Update Query Problem

This is a discussion on Update Query Problem within the pgsql Novice forums, part of the PostgreSQL category; --> the following update query... UPDATE t_job_number SET contract_id = 30 WHERE t_serial_number.serial_number_id = 78 AND t_serial_number.job_number_id = t_job_number.job_number_id yields ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 09:22 PM
operationsengineer1@yahoo.com
 
Posts: n/a
Default Update Query Problem

the following update query...

UPDATE t_job_number
SET contract_id = 30
WHERE t_serial_number.serial_number_id = 78
AND t_serial_number.job_number_id =
t_job_number.job_number_id

yields the following chastisement...

ERROR: missing FROM-clause entry for table
"t_serial_number"

can anyone point in the right direction? requiring a
from clause in this update seems a little bizarre to
me - so i'm sure i've botched something up pretty
good.

tia...

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 09:22 PM
Charley Tiggs
 
Posts: n/a
Default Re: Update Query Problem


On Dec 13, 2005, at 11:30 AM, <operationsengineer1@yahoo.com>
<operationsengineer1@yahoo.com> wrote:

> the following update query...
>
> UPDATE t_job_number
> SET contract_id = 30
> WHERE t_serial_number.serial_number_id = 78
> AND t_serial_number.job_number_id =
> t_job_number.job_number_id
>
> yields the following chastisement...
>
> ERROR: missing FROM-clause entry for table
> "t_serial_number"
>
> can anyone point in the right direction? requiring a
> from clause in this update seems a little bizarre to
> me - so i'm sure i've botched something up pretty
> good.
>
> tia...


There needs to be a reference to t_serial_number in the update clause:

UPDATE t_job_number, t_serial_number
SET contract_id = 30
WHERE t_serial_number.serial_number_id = 78
AND t_serial_number.job_number_id =
t_job_number.job_number_id

Charley

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 09:23 PM
Andreas Kretschmer
 
Posts: n/a
Default Re: Update Query Problem

operationsengineer1@yahoo.com <operationsengineer1@yahoo.com> schrieb:

> the following update query...
>
> UPDATE t_job_number
> SET contract_id = 30
> WHERE t_serial_number.serial_number_id = 78
> AND t_serial_number.job_number_id =
> t_job_number.job_number_id


Try this:


UPDATE t_job_number
SET contract_id = 30
WHERE job_number_id = (select job_number_id from t_serial_number where
serial_number_id = 78);


I'm not sure if i understand you corrently...


HTH, Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-17-2008, 09:23 PM
Jaime Casanova
 
Posts: n/a
Default Re: Update Query Problem

On 12/13/05, operationsengineer1@yahoo.com
<operationsengineer1@yahoo.com> wrote:
> the following update query...
>
> UPDATE t_job_number
> SET contract_id = 30
> WHERE t_serial_number.serial_number_id = 78
> AND t_serial_number.job_number_id =
> t_job_number.job_number_id
>
> yields the following chastisement...
>
> ERROR: missing FROM-clause entry for table
> "t_serial_number"
>
> can anyone point in the right direction? requiring a
> from clause in this update seems a little bizarre to
> me - so i'm sure i've botched something up pretty
> good.
>
> tia...
>


UPDATE t_job_number SET contract_id = 30
WHERE job_number_id IN (SELECT job_number_id
FROM t_serial_number
WHERE serial_number_id = 78);

or add a FROM clause to the update

--
Atentamente,
Jaime Casanova
(DBA: DataBase Aniquilator

---------------------------(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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-17-2008, 09:23 PM
Michael Fuhr
 
Posts: n/a
Default Re: Update Query Problem

On Tue, Dec 13, 2005 at 11:37:00AM -0600, Charley Tiggs wrote:
> There needs to be a reference to t_serial_number in the update clause:
>
> UPDATE t_job_number, t_serial_number
> SET contract_id = 30
> WHERE t_serial_number.serial_number_id = 78
> AND t_serial_number.job_number_id =
> t_job_number.job_number_id


No version of PostgreSQL that I tested (7.3 and later) allows that
syntax, and it's not shown in the documentation.

ERROR: syntax error at or near "," at character 20
LINE 1: UPDATE t_job_number, t_serial_number
^

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-17-2008, 09:23 PM
Charley Tiggs
 
Posts: n/a
Default Re: Update Query Problem

Ooops. apologies. I've been in mysql too long.

Charley

On Dec 13, 2005, at 11:49 AM, Michael Fuhr wrote:

> On Tue, Dec 13, 2005 at 11:37:00AM -0600, Charley Tiggs wrote:
>> There needs to be a reference to t_serial_number in the update
>> clause:
>>
>> UPDATE t_job_number, t_serial_number
>> SET contract_id = 30
>> WHERE t_serial_number.serial_number_id = 78
>> AND t_serial_number.job_number_id =
>> t_job_number.job_number_id

>
> No version of PostgreSQL that I tested (7.3 and later) allows that
> syntax, and it's not shown in the documentation.
>
> ERROR: syntax error at or near "," at character 20
> LINE 1: UPDATE t_job_number, t_serial_number
> ^
>
> --
> Michael Fuhr



---------------------------(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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-17-2008, 09:23 PM
operationsengineer1@yahoo.com
 
Posts: n/a
Default Re: Update Query Problem

man, you guys are ON IT! thanks. the following
worked like a charm:

UPDATE t_job_number
SET contract_id = 30
WHERE job_number_id = (select job_number_id from
t_serial_number where serial_number_id = 78);

i have to spend some time figuring out exactly where i
fumbled the ball the first time around...

thanks, everyone.

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-17-2008, 09:23 PM
Andreas Kretschmer
 
Posts: n/a
Default Re: Update Query Problem

operationsengineer1@yahoo.com <operationsengineer1@yahoo.com> schrieb:

> man, you guys are ON IT! thanks. the following
> worked like a charm:
>
> UPDATE t_job_number
> SET contract_id = 30
> WHERE job_number_id = (select job_number_id from
> t_serial_number where serial_number_id = 78);


Please read also the mail from 'Jaime Casanova', if the subselect
returns multiple rows.


Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-17-2008, 09:23 PM
operationsengineer1@yahoo.com
 
Posts: n/a
Default Re: Update Query Problem

--- Charley Tiggs <ctiggs@xpressdocs.com> wrote:

> Ooops. apologies. I've been in mysql too long.
>
> Charley
>
> On Dec 13, 2005, at 11:49 AM, Michael Fuhr wrote:
>
> > On Tue, Dec 13, 2005 at 11:37:00AM -0600, Charley

> Tiggs wrote:
> >> There needs to be a reference to t_serial_number

> in the update
> >> clause:
> >>
> >> UPDATE t_job_number, t_serial_number
> >> SET contract_id = 30
> >> WHERE t_serial_number.serial_number_id = 78
> >> AND t_serial_number.job_number_id =
> >> t_job_number.job_number_id

> >
> > No version of PostgreSQL that I tested (7.3 and

> later) allows that
> > syntax, and it's not shown in the documentation.
> >
> > ERROR: syntax error at or near "," at character

> 20
> > LINE 1: UPDATE t_job_number, t_serial_number
> > ^
> >
> > --
> > Michael Fuhr


actually, i've never used mysql (although that excuse
might be nice right now!). this was my first
update... and it didn't go very well. -lol-

as for "line 1", i knew that didn't work b/c i tried
it in pgadmin - mostly out of desparation. i guess i
inadvertantly copied it to my note. make no mistake,
the query didn't work even w/o that bad synta.!

hopefully i'll be able to build off the basic update
example provided earlier so i can avoid trouble going forward.

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

---------------------------(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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:21 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com