Обсуждение: update question

Поиск
Список
Период
Сортировка

update question

От
Matthew Peter
Дата:
<div id="RTEContent">I need a throw away value for an insert statement... example...<br /><br /> update table<br /> set
value= 1, value = 2, throw_away_value -- so i don't break the query<br /> where id = 1; <br /><br /> Thanks<br
/></div><p><hrsize="1" /><b>Yahoo! Personals</b><br /> Let fate take it's course directly to your email.<br /> See
who'swaiting for you <a href="http://us.rd.yahoo.com/evt=36106/*http://personals.yahoo.com 
 
">Yahoo! Personals</a>

Re: update question

От
Jaime Casanova
Дата:
On 12/5/05, Matthew Peter <survivedsushi@yahoo.com> wrote:
> I need a throw away value for an insert statement... example...
>
> update table
> set value = 1, value = 2, throw_away_value -- so i don't break the query
> where id = 1;
>
> Thanks
>

What do you mean by "throw away value"?

are you trying to update and if the row doesn't exist then insert? if
that is you can do a function in plpgsql and use exceptions for
that... there is an example in the manuals

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)


Re: update question

От
Matthew Peter
Дата:
<div id="RTEContent">it's in a loop so there's an extra comma at the end so i was thinking i could put in a throw away
valueto keep the update from breaking if there's an additional comma<br /><br /><b><i>Jaime Casanova
<systemguards@gmail.com></i></b>wrote:<blockquote class="replbq" style="border-left: 2px solid rgb(16, 16, 255);
margin-left:5px; padding-left: 5px;"> On 12/5/05, Matthew Peter  wrote:<br />> I need a throw away value for an
insertstatement... example...<br />><br />> update table<br />> set value = 1, value = 2, throw_away_value --
soi don't break the query<br />> where id = 1;<br />><br />> Thanks<br />><br /><br />What do you mean by
"throwaway value"?<br /><br />are you trying to update and if the row doesn't exist then insert? if<br />that is you
cando a function in plpgsql and use exceptions for<br />that... there is an example in the manuals<br /><br />--<br
/>regards,<br/>Jaime Casanova<br />(DBA: DataBase Aniquilator ;)<br /><br />---------------------------(end of
broadcast)---------------------------<br/>TIP 4: Have you searched our list archives?<br /><br />
http://archives.postgresql.org<br/></blockquote><br /></div><p><hr size="1" /><b>Yahoo! Personals</b><br /> Single?
There'ssomeone we'd like you to meet.<br /> Lots of someones, actually. <a
href="http://us.rd.yahoo.com/evt=36108/*http://personals.yahoo.com
 
">Yahoo! Personals</a>

Re: update question

От
Matthew Peter
Дата:
<div id="RTEContent">Like WHERE 1 = 1, but in UPDATE table SET value = 1, 1 = 1;<br /></div><p><hr size="1" /><b>Yahoo!
Personals</b><br/> Single? There's someone we'd like you to meet.<br /> Lots of someones, actually. <a
href="http://us.rd.yahoo.com/evt=36108/*http://personals.yahoo.com
 
">Try Yahoo! Personals</a>

Re: update question

От
Jaime Casanova
Дата:
On 12/5/05, Matthew Peter <survivedsushi@yahoo.com> wrote:
> it's in a loop so there's an extra comma at the end so i was thinking i
> could put in a throw away value to keep the update from breaking if there's
> an additional comma
>
> Jaime Casanova <systemguards@gmail.com> wrote:
> On 12/5/05, Matthew Peter wrote:
> > I need a throw away value for an insert statement... example...
> >
> > update table
> > set value = 1, value = 2, throw_away_value -- so i don't break the query
> > where id = 1;
> >
> > Thanks
> >
>

i guess you are constructing the query in a string and EXECUTEd it...
if that is the case review your logic...




--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)


Re: update question

От
Tom Lane
Дата:
Matthew Peter <survivedsushi@yahoo.com> writes:
> it's in a loop so there's an extra comma at the  end so i was thinking i could put in a throw away value to keep the
updatefrom breaking if there's an additional comma
 

The best thing is to fix your loop logic.  Usually it's not hard to emit
a comma only if one is needed.

If you're intent on using a broken loop, you could do "foo = foo" where
foo is any table column you didn't yet assign to.  Consider though the
corner case where you've already assigned all the columns.  Best bet
is to fix your loop...
        regards, tom lane