Re: How do I enabled Windows 10 to be able to run PSQL etc
Steve Midgley <[email protected]> Thu, 12 Sep 2019 13:22:18 +0100
| Newsgroups | gmane.comp.db.postgresql.sql |
|---|---|
| Message-ID | <CAJexoSLpKMS12WHe7T5Fujvw_umZ5vdt6v-cCxRQfObaHZYo7g@mail.gmail.com> |
--000000000000f8663c05925a305c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Sep 12, 2019 at 1:17 PM Karen Goh <[email protected]> wrote: > > > > Sent from Yahoo Mail for iPhone > <https://overview.mail.yahoo.com/?.src=3DiOS> > > On Thursday, September 12, 2019, 8:07 PM, Steve Midgley < > [email protected]> wrote: > > On Thu, Sep 12, 2019 at 11:50 AM Karen Goh <[email protected]> wrote: > > Anyway, now my problem is that i get a > > org.postgresql.util.PSQLException: ERROR: null value in column "parent_id= " > violates not-null constraint > > I'd like to know since I have already made parent_id a primary key, do I > need to put a idenity as ALWAYS and increment by 1 ? > > cos another table I had used pgAdmin4 to define it as identity, ALWAYS, > increment 1 and it works well.... > > so what is the difference between identity and PRIMARY KEY ? > > and if I follow the other table definition for id and put in the ALWAYS, > it will give me another problem...that the generated_id doesn't get > inserted even though it should not > > > Hi Karen, > > Please bottom post on this forum - it's uncommon these days, but the > custom on this email list to post replies at the bottom of the email. > > Regarding your question about nulls and primary keys -- yes you want to > define, where it makes sense, to use autoincrementing primary keys, if yo= u > want the system to manage your keys. Note that autoincrementing IDs, if > exposed to the public via the web or similar, could create some security > issues. > > Hi Steve, > > Sorry yahoo mail is giving me lots of problems in typing at the bottom - > the convention. > > I would like to confirm how to make an ID in PostgreSQL auto increment > like MySQL? > > And since I need to have generated key to be retrieved before inserting > into the join table, if I don=E2=80=99t do it via web how can I do it the= n? > > But in many cases it makes a lot of sense to use them. To create a primar= y > key that autoincrements, use the "serial" or "bigserial" datatype. Combin= ed > with a primary key (that enforces "not null" among other things), your > create table would look like this: > > CREATE TABLE sample ( > id SERIAL PRIMARY KEY,); > > Why is my another table, without making the id serial it is auto-incremen= ting? > > > I have not tested it, but I'd guess you should be able to alter a table t= hat has an integer primary key and convert it to a serial. I hope that's he= lpful! Steve > > Send us the "DDL" for your table and we might be able to help. PgAdmin4 should be able to give you the create table statement that would create the table that is autoincrementing without a serial datatype that you can share with us, and probably someone can answer that question. It is possible to make fields autoincrement using other methods, iirc. Steve --000000000000f8663c05925a305c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">= <div dir=3D"ltr" class=3D"gmail_attr">On Thu, Sep 12, 2019 at 1:17 PM Karen= Goh <<a href=3D"mailto:[email protected]">[email protected]</a>&g= t; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0p= x 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div> <br><br><br><a href=3D"https://overview.mail.yahoo.com/?.src=3DiOS" target= =3D"_blank">Sent from Yahoo Mail for iPhone</a><br><br><p class=3D"gmail-m_= -2527352593038415746yahoo-quoted-begin" style=3D"font-size:15px;color:rgb(1= 13,95,250);padding-top:15px;margin-top:0px">On Thursday, September 12, 2019= , 8:07 PM, Steve Midgley <<a href=3D"mailto:[email protected]" target= =3D"_blank">[email protected]</a>> wrote:</p><blockquote class=3D"gmail= -m_-2527352593038415746iosymail"><div id=3D"gmail-m_-2527352593038415746yiv= 0946157834"><div><div dir=3D"ltr"><div class=3D"gmail-m_-252735259303841574= 6yiv0946157834gmail_quote"><div class=3D"gmail-m_-2527352593038415746yiv094= 6157834gmail_attr" dir=3D"ltr">On Thu, Sep 12, 2019 at 11:50 AM Karen Goh &= lt;<a rel=3D"nofollow" shape=3D"rect" href=3D"mailto:[email protected]" = target=3D"_blank">[email protected]</a>> wrote:<br clear=3D"none"></d= iv><blockquote class=3D"gmail-m_-2527352593038415746yiv0946157834gmail_quot= e" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204)= ;padding-left:1ex"><div> Anyway, now my problem is that i ge= t a <br clear=3D"none"><br clear=3D"none">org.postgresql.util.PSQLException= : ERROR: null value in column "parent_id" violates not-null const= raint<br clear=3D"none"><br clear=3D"none">I'd like to know since I hav= e already made parent_id a primary key, do I need to put a idenity as ALWAY= S and increment by 1 ?<br clear=3D"none"><br clear=3D"none">cos another tab= le I had used pgAdmin4 to define it as identity, ALWAYS, increment 1 and it= works well....<br clear=3D"none"><br clear=3D"none">so what is the differe= nce between identity and PRIMARY KEY ?<br clear=3D"none"><br clear=3D"none"= >and if I follow the other table definition for id and put in the ALWAYS, i= t will give me another problem...that the generated_id doesn't get inse= rted even though it should not </div></blockquote><div><br clear=3D"none"><= /div><div>Hi Karen,</div><div><br clear=3D"none"></div><div>Please bottom p= ost on this forum - it's uncommon these days, but the custom on this em= ail list to post replies at the bottom of the email.</div><div><br clear=3D= "none"></div><div>Regarding your question about nulls and primary keys -- y= es you want to define, where it makes sense, to use autoincrementing primar= y keys, if you want the system to manage your keys. Note that autoincrement= ing IDs, if exposed to the public via the web or similar, could create some= security issues.</div><div><br></div><div>Hi Steve,</div><div><br></div><d= iv>Sorry yahoo mail is giving me lots of problems in typing at the bottom -= the convention.=C2=A0</div><div><br></div><div>I would like to confirm how= to make an ID =C2=A0in PostgreSQL auto increment like MySQL?</div><div><br= ></div><div>And since I need to have generated key to be retrieved before i= nserting into the join table, if I don=E2=80=99t do it via web how can I do= it then?=C2=A0</div><div><br clear=3D"none"></div><div>But in many cases i= t makes a lot of sense to use them. To create a primary key that autoincrem= ents, use the "serial" or "bigserial" datatype. Combine= d with a primary key (that enforces "not null" among other things= ), your create table would look like this:</div><div> <div class=3D"gmail-m_-2527352593038415746yiv0946157834gmail-language-sql g= mail-m_-2527352593038415746yiv0946157834gmail-highlighter-rouge"><div class= =3D"gmail-m_-2527352593038415746yiv0946157834gmail-highlight"><pre class=3D= "gmail-m_-2527352593038415746yiv0946157834gmail-highlight"><code><span clas= s=3D"gmail-m_-2527352593038415746yiv0946157834gmail-k">CREATE</span> <span = class=3D"gmail-m_-2527352593038415746yiv0946157834gmail-k">TABLE</span> sam= ple <span class=3D"gmail-m_-2527352593038415746yiv0946157834gmail-p">(</spa= n> <span class=3D"gmail-m_-2527352593038415746yiv0946157834gmail-n">id</span= > <span class=3D"gmail-m_-2527352593038415746yiv0946157834gmai= l-n">SERIAL</span> <span class=3D"gmail-m_-2527352593038415746yiv0946157834= gmail-k">PRIMARY</span> <span class=3D"gmail-m_-2527352593038415746yiv09461= 57834gmail-k">KEY</span><span class=3D"gmail-m_-2527352593038415746yiv09461= 57834gmail-p">,</span> <span class=3D"gmail-m_-2527352593038415746yiv0946157834gmail-p">);</span><= br clear=3D"none"><br clear=3D"none"></code></pre><pre class=3D"gmail-m_-25= 27352593038415746yiv0946157834gmail-highlight"><code>Why is my another tabl= e, without making the id serial it is auto-incrementing?</code></pre><pre c= lass=3D"gmail-m_-2527352593038415746yiv0946157834gmail-highlight"><code><br= ></code></pre><pre class=3D"gmail-m_-2527352593038415746yiv0946157834gmail-= highlight"><code><span style=3D"font-family:arial,sans-serif">I have not te= sted it, but I'd guess you should be able to alter a table that has an = integer primary key and convert it to a serial. I hope that's helpful! = Steve</span><div class=3D"gmail-m_-2527352593038415746yiv0946157834yqt50227= 32543" id=3D"gmail-m_-2527352593038415746yiv0946157834yqtfd17374"><br clear= =3D"none"></div></code></pre></div></div></div></div></div></div></div></bl= ockquote></div></blockquote><div><br></div><div>Send us the "DDL"= for your table and we might be able to help. PgAdmin4 should be able to gi= ve you the create table statement that would create the table that is autoi= ncrementing without a serial datatype that you can share with us, and proba= bly someone can answer that question. It is possible to make fields autoinc= rement using other methods, iirc. Steve<br></div></div></div> --000000000000f8663c05925a305c--