Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > Re: Primary Key...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 15120 of 17600
Post > Topic >>

Re: Primary Key with serial the solution?

by xanaruto@[EMAIL PROTECTED] ("x asasaxax") Apr 1, 2008 at 08:26 AM

------=_Part_24976_28098451.1207049204515
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

How about if i do this inside a procedure:

SELECT setval('sequence',(SELECT max(id) FROM table)) INTO variable;
insert into table values(variable, ..., ...);  ?

Will this be transactional? Cause, they say that setval is a command
that its transactional. Using this way i
don=B4t will need to use a sequence anymore. Is that correct?


Thanks you all.



2008/3/31, x asasaxax <xanaruto@[EMAIL PROTECTED]
>:
>
> can anyone do a example for me.. an explain how it works?
>
> Thanks a lot
>
>
> 2008/3/29, Berend Tober <btober@[EMAIL PROTECTED]
>:
> >
> > x asasaxax wrote:
> > >    I have the following table    create table product(cod serial,
> > user_cod
> > > bigint, constraint product_fk Foreign Key(user_cod) references
> > user(cod),
> > > constraint product_pk Primary Key(cod, user_cod));
> > >
> > > What i want to happend is that:
> > > user_cod            cod
> > > 1                         1
> > > 1                         2
> > > 1                         3
> > > 2                         1
> > > 3                         1
> > > 3                         2
> > >
> > > Can serial do that? ...
> >
> > No.
> >
> > > ...what can  i do to make this happen?
> >
> >
> > http://archives.postgresql.org/pgsql-general/2006-08/msg00744.php
> >
> >
> >
>

------=_Part_24976_28098451.1207049204515
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<pre><code class=3D"sql">How about if i do this inside a
procedure:<br><br>=
SELECT setval(&#39;sequence&#39;,(SELECT max(id) FROM table)) INTO
variable=
;<br>insert into table values(variable, ..., ...);  ?<br><br>Will this be
t=
ransactional? Cause, they say that setval is a command that its
transaction=
al. Using this way i<br>
don=B4t will need to use a sequence anymore. Is that
correct?<br><br><br>Th=
anks you all.<br></code></pre><br><br><div><span
class=3D"gmail_quote">2008=
/3/31, x asasaxax &lt;<a
href=3D"mailto:xanaruto@[EMAIL PROTECTED]
">xanaruto@[EMAIL PROTECTED]
>&gt;:</span><blockquote class=3D"gmail_quote" style=3D"border-left:
=
1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left:
1ex;=
">
<div>can anyone do a example for me.. an explain how it works?</div>
<div>&nbsp;</div>
<div>Thanks a lot<br><br>&nbsp;</div>
<div><span class=3D"gmail_quote">2008/3/29, Berend Tober &lt;<a
href=3D"mai=
lto:btober@[EMAIL PROTECTED]
" target=3D"_blank" onclick=3D"return
top.js.Ope=
nExtLink(window,event,this)">btober@[EMAIL PROTECTED]
>&gt;:</span><div><s=
pan class=3D"e" id=3D"q_11905c1685a7f398_1">
<blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204,
=
204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">x asasaxax
wrote:=
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;I have the following
table&nbsp;&nbsp;&nbsp=
;&nbsp;create table product(cod serial, user_cod<br>
&gt; bigint, constraint product_fk Foreign Key(user_cod) references
user(co=
d),<br>
&gt; constraint product_pk Primary Key(cod, user_cod));<br>&gt;<br>&gt;
Wha=
t i want to happend is that:<br>&gt;
user_cod&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cod<br>&gt;
1&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br>&gt;
1&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<br>&gt;
1&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3<br>

&gt;
2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
 1<br>&gt;
3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp; 1<br>&gt;
3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp; 2<br>&gt;<br>&gt; Can serial do that?
...<br><br>No.<br><br>&g=
t; ...what can&nbsp;&nbsp;i do to make this happen?<br><br><br><a
href=3D"h=
ttp://archives.postgresql.org/pgsql-general/2006-08/msg00744.php"
target=3D=
"_blank" onclick=3D"return
top.js.OpenExtLink(window,event,this)">http://ar=
chives.postgresql.org/pgsql-general/2006-08/msg00744.php</a><br>

<br><br></blockquote></span></div></div><br>
</blockquote></div><br>

------=_Part_24976_28098451.1207049204515--
 




 2 Posts in Topic:
Re: Primary Key with serial the solution?
xanaruto@[EMAIL PROTECTED  2008-04-01 08:26:44 
Re: Primary Key with serial the solution?
craig@[EMAIL PROTECTED]   2008-04-02 11:12:23 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 13:04:31 CST 2008.