Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hpDtq-0004Qd-Mi for pgsql-admin@arkaria.postgresql.org; Sun, 21 Jul 2019 15:37:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hpDto-0004fM-AT for pgsql-admin@arkaria.postgresql.org; Sun, 21 Jul 2019 15:37:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hpDtn-0004fF-Vt for pgsql-admin@lists.postgresql.org; Sun, 21 Jul 2019 15:37:20 +0000 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hpDth-0004Zj-Oi for pgsql-admin@lists.postgresql.org; Sun, 21 Jul 2019 15:37:19 +0000 Received: by mail-ot1-x333.google.com with SMTP id r21so31606312otq.6 for ; Sun, 21 Jul 2019 08:37:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:cc:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=u6/cY6NCWobGoX8/dUyJ2cDBpau6wsgwLF8H3VnMX/o=; b=AZcNGJMKNZpI99i+335t8w9LXOa4iu4iYF0cnSFCroFgMYe24l35tRcuscvKk3QhXN wcGGBzGe0175foOb2aka3pOfipouWnu+FgBTCTBOinMt5MP0Y5r5RFiLAYXp9t5/+KEU 7KYaEYa0QhalXgtBxjeZq5hNVNXnofZbdVkEPOFAwoQalKE3fQF1lbYl8tboLquSRW6n qSGXuDj/mb2ei0qPjL28bucl7H8aMdbHv6yHEdI1cwzB0MNXGdxizFXmnVLvXavt5Eid X8BWqH4vuoayGXVRZOZ8D0Wu9JqrR3ngn4Hpg3JooHO/xgA7EOEMemeNHiSd/pSXsFKM ft9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=u6/cY6NCWobGoX8/dUyJ2cDBpau6wsgwLF8H3VnMX/o=; b=q5REo009dEMtbkwuTGNhXPzEvG2nbu3K5dq2sz+7L212VjJ1sB3b0ccCYbTz1Uegu4 oH28cqvQcV7jf+RVT5xVQ7ORgwqDysAfjWDEZp+nmELd0UUk6Is4XLLiU/1my+6YiDNF nGDT52xhCijqqVOa9houwNSHAkJu5H/ZmMyqEOs66qpP6oGzZu6gpdWGRNudw0Ehg8Ah AwbPRkBf+unWUzPQ7LigcCBihgrpLCfRWS98xqBWalzrxMir3auJXYwnFd3rn8lo5wbG lpgzxQ+RPuBQCjeEm4YfOqu8IA6aycy/6nbJzDeayxnug2Py+mQKzLFMlkGypezyJL45 sFKA== X-Gm-Message-State: APjAAAV7JdxZR98E5NxicLX3m1Eh8ya46nyBLsNMk39FLlffaJ771O58 DKcO8jl0uipTOYGfGR9J/6bbiqhQ14s= X-Google-Smtp-Source: APXvYqycCzeDsVP86n++bPq4Du8PUlr/zONP1J4MzgaHzk36RO2wYwpcF8RAFAkrMhgAX3enXFlzyg== X-Received: by 2002:a9d:70da:: with SMTP id w26mr45887993otj.270.1563723430750; Sun, 21 Jul 2019 08:37:10 -0700 (PDT) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id h60sm13435130otb.29.2019.07.21.08.37.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Jul 2019 08:37:10 -0700 (PDT) Subject: Re: How do I alter an existing column and add a foreign key which is a Primary key to a table? Cc: pgsql-admin@lists.postgresql.org References: <820008379.2579287.1563670685484@mail.yahoo.com> <5CE41E80-274A-44DA-9553-E2DCA260F751@jakobs.com> <385857992.2643116.1563717238725@mail.yahoo.com> <923fb3b1-90e9-e0b5-bc5b-d896128c3f28@gmail.com> <1745586001.2633224.1563719075867@mail.yahoo.com> <905425626.2686338.1563721213121@mail.yahoo.com> <2030754658.2646264.1563721831668@mail.yahoo.com> <75125c45-0fed-e5f1-50f0-9646db20dde6@gmail.com> <927283546.2681887.1563722628862@mail.yahoo.com> From: Ron Message-ID: <931856e7-528d-35e5-3b9d-2e972a7df3a6@gmail.com> Date: Sun, 21 Jul 2019 10:37:09 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <927283546.2681887.1563722628862@mail.yahoo.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 7/21/19 10:23 AM, Karen Goh wrote: > > On Sunday, July 21, 2019, 11:13:58 PM GMT+8, Ron > wrote: > > > On 7/21/19 10:10 AM, Karen Goh wrote: [snip] > > > > Here is a compressed format : > > > > s_tutor > > -------- > > zipcode(text) > > tutor_id (I just checked this is becomes a 'serial id ?' based on the > > generated sql > > > > ALTER TABLE public.s_tutor ALTER COLUMN tutor_id ADD GENERATED BY DEFAULT > > AS IDENTITY ( > > SEQUENCE NAME public.tutor_strtutorid_seq > > START WITH 1 > > INCREMENT BY 1 > > NO MINVALUE > > NO MAXVALUE > > CACHE 1 > > ); > > > > tutor_subject > > ---------------- > > tutor_id > > subject_Names > > > select s_tutor.zipcode > from s_tutor, tutor_subject > where s_tutor.tutor_id = tutor_subject.tutor_id > and tutor_subject.subject_names ='Angela Merkel' > > Hi Ron, > > Could you explain why you select s_tutor.zipcode from tutor_subject since > there is no zipcode inside tutor_subject? > I did not do what you think I did. > Perhaps my reasoning is wrong and I really want to have your expert view. It might sound harsh, but is not meant to be: this list is for administering PostgreSQL, not teaching basic SQL. -- Angular momentum makes the world go 'round.