Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ejrcF-0005sU-1R for pgsql-general@arkaria.postgresql.org; Thu, 08 Feb 2018 19:12:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ejrcD-00044d-VM for pgsql-general@arkaria.postgresql.org; Thu, 08 Feb 2018 19:12:13 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ejrcD-00044T-NW for pgsql-general@lists.postgresql.org; Thu, 08 Feb 2018 19:12:13 +0000 Received: from mail-qk0-x241.google.com ([2607:f8b0:400d:c09::241]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ejrcA-0001yJ-92 for pgsql-general@lists.postgresql.org; Thu, 08 Feb 2018 19:12:13 +0000 Received: by mail-qk0-x241.google.com with SMTP id 15so7017886qkl.3 for ; Thu, 08 Feb 2018 11:12:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:in-reply-to:message-id:references:user-agent :mime-version; bh=CDW2Cvrpj1R1DjtOj+n8Yhea7z4s1uZSFVetwpqld/M=; b=HqrZ9o2Rs5uFOdtx3W0/e5JRj2U+sopWE6xidvoqinvVeLbBdud0OCXLCmmVInDntN i7yXqJbAqJYo0Cluo03nqx06FMR1ys2P76EaIEMo/+IIs4ZvbDGCkgn7sKwIl4fOUKF8 XLMdbdnEeLpcV5JR9OVqZW/GLPP3wP/fxDCnIfITfWm30Q90Hs9AsjKBhFPI+TUK39Q2 UY8+DBsjPqQcm/Z3VO/k6Z7tT+Xgx8gQUbHcALUsqQJZ2gVbQG15OdTHuO7PJYe/oEW6 Br6eeqkUH2aSSb3NbppcIVQAwYEdzYYS+WIkR4MInTLtT3WShM8ELqHJhCJHO3WXqr1b F5+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=CDW2Cvrpj1R1DjtOj+n8Yhea7z4s1uZSFVetwpqld/M=; b=Nw7o0QXq4eytTykLDxQRCEdIvpdNrckZVDp5xGaYzYADVlCN/0S6FJ2YqF1lt0eUDQ TkM1yzGbUFJiKHCB22Q7RsVZ2PuDwwuluIfliirkOipAp2G2lZ3fzvvbAwz9IaEvIhso 2djVTJOK9E+D9YvInGCBC2JK+lD2q3v9/hB4PmwW3fJOXu9qOXUB5Vu51z/AltDLTQzy 0QPISj+HDd/AcHDojLBT5NoPhJkYMWC6ojYrs7ku/LNK1IPtXJU0doocQ4EmPHPW49Sd 5WGW8BphXoqhvKv6cKNMGWJvFT8S8r6/TY1bhZsIgegX5A4KS1xUUSXWHa6CW9uV0pQa X4iw== X-Gm-Message-State: APf1xPBdHEIJs7aK4vrzb9TNOQSwGc0wf76gswtPo6NVul6G4hMCx1AM veUAN7euTO0YHi317qo19kVP1g== X-Google-Smtp-Source: AH8x226pihttqjlU6gMDC2mVHjI3CWlCaJZ2U6m5/Cp96vrKYzpS6vxBBL6v2/+E/NoWyU67VSpAOA== X-Received: by 10.55.50.141 with SMTP id y135mr66745qky.165.1518117128623; Thu, 08 Feb 2018 11:12:08 -0800 (PST) Received: from [192.168.245.27] ([65.183.149.206]) by smtp.gmail.com with ESMTPSA id v60sm456786qte.43.2018.02.08.11.12.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Feb 2018 11:12:08 -0800 (PST) Date: Thu, 8 Feb 2018 14:12:07 -0500 (EST) From: Steven Hirsch X-X-Sender: hirsch@z87 To: pgsql-general@lists.postgresql.org Subject: Re: Odd behavior with 'currval' In-Reply-To: Message-ID: References: <31344c43-4f1d-78bd-1a07-4e4e544a1deb@aklaver.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="8323329-1455901898-1518117127=:5809" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-1455901898-1518117127=:5809 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8BIT On Thu, 8 Feb 2018, Adrian Klaver wrote: > hplc=> \d student_attendance_attendance_id_seq > Sequence "public.student_attendance_attendance_id_seq" > Column | Type | Value > ---------------+---------+-------------------------------------- > sequence_name | name | student_attendance_attendance_id_seq > last_value | bigint | 39590 > start_value | bigint | 1 > increment_by | bigint | 1 > max_value | bigint | 9223372036854775807 > min_value | bigint | 1 > cache_value | bigint | 1 > log_cnt | bigint | 0 > is_cycled | boolean | f > is_called | boolean | t > Owned by: public.student_attendance.attendance_id > Assuming you showed the complete output I am not seeing the Owned by: for > your sequence. I would do the \d on one of your sequences that 'works', I am > guessing you will see Owned by: . > > To correct see: > > https://www.postgresql.org/docs/10/static/sql-altersequence.html > > "OWNED BY table_name.column_name > OWNED BY NONE > > The OWNED BY option causes the sequence to be associated with a specific > table column, such that if that column (or its whole table) is dropped, the > sequence will be automatically dropped as well. If specified, this > association replaces any previously specified association for the sequence. > The specified table must have the same owner and be in the same schema as the > sequence. Specifying OWNED BY NONE removes any existing association, making > the sequence “free-standing”. Agggh. That's it! I'll fix the ownership. So, a few questions: 1. How on earth did this happen? I do not recall doing any manual fiddling with either database - they were (as far as I know) built from the same DDL. We may never have an answer for this. Being human, who knows what I may or may not have done 4 months ago... But, 2. Why is the currval() function being so blasted dumb? If 'pg_get_serial_sequence' cannot resolve the sequence, it returns NULL. As such, shouldn't the outer currval() also be returning NULL? I cannot imagine a rationale for the current behavior. THANKS to everyone who chimed in on this. I was beginning to think I was losing my marbles. -- --8323329-1455901898-1518117127=:5809--