Re: Odd behavior with 'currval'

From: Melvin Davidson <melvin6925(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: Steven Hirsch <snhirsch(at)gmail(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Odd behavior with 'currval'
Date: 2018-02-08 18:31:47
Message-ID: CANu8FizM63cA9qpoXfiTmx=c=7RB+PQTmU_6P_hJ0-VJ5chU_A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Feb 8, 2018 at 1:27 PM, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
wrote:

> On 02/08/2018 10:20 AM, Steven Hirsch wrote:
>
>> On Thu, 8 Feb 2018, Adrian Klaver wrote:
>>
>> What if you do?:
>>>
>>> SELECT * FROM udm_asset_type_definition_def_id_seq;
>>>
>>
>> I get:
>>
>> udm_asset_type_definition_def_id_seq 21 1 1
>> 9223372036854775807 1 1 32 false true
>>
>>
>> SELECT currval('udm_asset_type_definition_id_seq');
>>>
>>
> Arrgh my mistake, the above should have been
>
> SELECT currval('udm_asset_type_definition_def_id_seq');
>
>
>
>> I get:
>>
>> [Code: , SQL State: 42P01] ERROR: relation "udm_asset_type_definition_id_seq"
>> does not exist
>> Position: 16
>>
>> Also what happens if you do:
>>>
>>> pg_dump -d db_name -U some_user -s -t udm_asset_type_definition >
>>> out.sql
>>>
>>
>> This:
>>
>> --
>> -- Name: udm_asset_type_definition; Type: TABLE; Schema: main; Owner:
>> asset_registry_admins
>> --
>>
>> CREATE TABLE udm_asset_type_definition (
>> def_id bigint DEFAULT nextval('udm_asset_type_definition_def_id_seq'::regclass)
>> NOT NULL,
>> def_name character varying(32) NOT NULL,
>> );
>>
>>
>> ALTER TABLE udm_asset_type_definition OWNER TO asset_registry_admins;
>>
>> --
>> -- Name: udm_asset_type_definition udm_asset_type_definition_def_name_key;
>> Type: CONSTRAINT; Schema: main; Owner: asset_registry_admins
>> --
>>
>> ALTER TABLE ONLY udm_asset_type_definition
>> ADD CONSTRAINT udm_asset_type_definition_def_name_key UNIQUE
>> (def_name);
>>
>> --
>> -- Name: udm_asset_type_definition; Type: ACL; Schema: main; Owner:
>> asset_registry_admins
>> --
>>
>> GRANT SELECT ON TABLE udm_asset_type_definition TO asset_registry_readers;
>> GRANT ALL ON TABLE udm_asset_type_definition TO asset_registry_writers;
>>
>>
>>
>>
>>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com
>
>
*FYI, further down in Sequence Manipulation Functions is*

*" **currval*

*Return the value most recently obtained by nextval for this sequence in
the current session. (An error is reported if nextval has never been called
for this sequence in this session.) Because this is returning a
session-local value, it gives a predictable answer whether or not other
sessions have executed nextval since the current session did.*

* " *

--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Francisco Olarte 2018-02-08 18:34:02 Re: Odd behavior with 'currval'
Previous Message Adrian Klaver 2018-02-08 18:31:24 Re: Odd behavior with 'currval'