Re: How do I enabled Windows 10 to be able to run PSQL etc
Karen Goh <[email protected]> Thu, 12 Sep 2019 12:17:34 +0000 (UTC)
| Newsgroups | gmane.comp.db.postgresql.sql |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_4161365_155574332.1568290654775 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sent from Yahoo Mail for iPhone 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=20 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 ne= ed to put a idenity as ALWAYS and increment by 1 ? cos another table I had used pgAdmin4 to define it as identity, ALWAYS, inc= rement 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=20 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 def= ine, where it makes sense, to use autoincrementing primary keys, if you wan= t the system to manage your keys. Note that autoincrementing IDs, if expose= d 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 - th= e convention.=C2=A0 I would like to confirm how to make an ID =C2=A0in PostgreSQL auto incremen= t like MySQL? And since I need to have generated key to be retrieved before inserting int= o the join table, if I don=E2=80=99t do it via web how can I do it then?=C2= =A0 But in many cases it makes a lot of sense to use them. To create a primary = key that autoincrements, use the "serial" or "bigserial" datatype. Combined= with a primary key (that enforces "not null" among other things), your cre= ate 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-incrementi= ng? I have not tested it, but I'd guess you should be able to alter a table tha= t has an integer primary key and convert it to a serial. I hope that's help= ful! Steve ------=_Part_4161365_155574332.1568290654775 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <html xmlns=3D"http://www.w3.org/1999/xhtml" xmlns:v=3D"urn:schemas-microso= ft-com:vml" xmlns:o=3D"urn:schemas-microsoft-com:office:office"><head><!--[= if gte mso 9]><xml><o:OfficeDocumentSettings><o:AllowPNG/><o:PixelsPerInch>= 96</o:PixelsPerInch></o:OfficeDocumentSettings></xml><![endif]--></head><bo= dy> <br><br><br><a href=3D"https://overview.mail.yahoo.com/?.src=3DiOS">Sent fr= om Yahoo Mail for iPhone</a><br><br><p class=3D"yahoo-quoted-begin" style= =3D"font-size: 15px; color: #715FFA; padding-top: 15px; margin-top: 0">On T= hursday, September 12, 2019, 8:07 PM, Steve Midgley <[email protected]&= gt; wrote:</p><blockquote class=3D"iosymail"><div id=3D"yiv0946157834"><div= ><div dir=3D"ltr"><div class=3D"yiv0946157834gmail_quote"><div class=3D"yiv= 0946157834gmail_attr" dir=3D"ltr">On Thu, Sep 12, 2019 at 11:50 AM Karen Go= h <<a rel=3D"nofollow" shape=3D"rect" ymailto=3D"mailto:karenworld@yahoo= .com" target=3D"_blank" href=3D"mailto:[email protected]">karenworld@yah= oo.com</a>> wrote:<br clear=3D"none"></div><blockquote class=3D"yiv09461= 57834gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid r= gb(204,204,204);padding-left:1ex;"><div> Anyway, now my prob= lem is that i get a <br clear=3D"none"><br clear=3D"none">org.postgresql.ut= il.PSQLException: ERROR: null value in column "parent_id" violates not-null= constraint<br clear=3D"none"><br clear=3D"none">I'd like to know since I h= ave already made parent_id a primary key, do I need to put a idenity as ALW= AYS and increment by 1 ?<br clear=3D"none"><br clear=3D"none">cos another t= able 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 diffe= rence between identity and PRIMARY KEY ?<br clear=3D"none"><br clear=3D"non= e">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 insert= ed even though it should not </div></blockquote><div><br clear=3D"none"></d= iv><div>Hi Karen,</div><div><br clear=3D"none"></div><div>Please bottom pos= t on this forum - it's uncommon these days, but the custom on this email li= st 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 -- yes you= want to define, where it makes sense, to use autoincrementing primary keys= , if you want the system to manage your keys. Note that autoincrementing ID= s, if exposed to the public via the web or similar, could create some secur= ity issues.</div><div><br></div><div>Hi Steve,</div><div><br></div><div>Sor= ry yahoo mail is giving me lots of problems in typing at the bottom - the c= onvention. </div><div><br></div><div>I would like to confirm how to ma= ke an ID in PostgreSQL auto increment like MySQL?</div><div><br></div= ><div>And since I need to have generated key to be retrieved before inserti= ng into the join table, if I don=E2=80=99t do it via web how can I do it th= en? </div><div><br clear=3D"none"></div><div>But in many cases it make= s a lot of sense to use them. To create a primary key that autoincrements, = use the "serial" or "bigserial" datatype. Combined with a primary key (that= enforces "not null" among other things), your create table would look like= this:</div><div> <div class=3D"yiv0946157834gmail-language-sql yiv0946157834gmail-highlighte= r-rouge"><div class=3D"yiv0946157834gmail-highlight"><pre class=3D"yiv09461= 57834gmail-highlight"><code><span class=3D"yiv0946157834gmail-k">CREATE</sp= an> <span class=3D"yiv0946157834gmail-k">TABLE</span> sample <span class=3D= "yiv0946157834gmail-p">(</span> <span class=3D"yiv0946157834gmail-n">id</span> <span class= =3D"yiv0946157834gmail-n">SERIAL</span> <span class=3D"yiv0946157834gmail-k= ">PRIMARY</span> <span class=3D"yiv0946157834gmail-k">KEY</span><span class= =3D"yiv0946157834gmail-p">,</span> <span class=3D"yiv0946157834gmail-p">);</span><br clear=3D"none"><br clear= =3D"none"></code></pre><pre class=3D"yiv0946157834gmail-highlight"><code>Wh= y is my another table, without making the id serial it is auto-incrementing= ?</code></pre><pre class=3D"yiv0946157834gmail-highlight"><code><br></code>= </pre><pre class=3D"yiv0946157834gmail-highlight"><code><span style=3D"font= -family:arial, sans-serif;">I have not tested 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"yiv0946157834yqt= 5022732543" id=3D"yiv0946157834yqtfd17374"><br clear=3D"none"></div></code>= </pre></div></div><div class=3D"yiv0946157834yqt5022732543" id=3D"yiv094615= 7834yqtfd90837"> </div></div></div></div></div></div><blockquote></blockquote></blockquote> </body></html> ------=_Part_4161365_155574332.1568290654775--