Re: sequences what does ::text mean ? - Mailing list pgsql-novice

From Tom Lane
Subject Re: sequences what does ::text mean ?
Date
Msg-id 24970.1025709629@sss.pgh.pa.us
Whole thread Raw
In response to Re: sequences what does ::text mean ?  (Josh Jore <josh@lavendergreens.org>)
Responses Re: sequences what does ::text mean ?  (Josh Jore <josh@lavendergreens.org>)
List pgsql-novice
Josh Jore <josh@lavendergreens.org> writes:
> My understanding (which was largely
> guessing after watching Josh Berkus) was that the atom 'seq_auteurs' is
> considered to be of unknown type until it is needed for evaluation in an
> expression. During evaluation the value is coerced into something more
> specific. My thought was that if the value is pre-coerced then that saves
> a run-time step.

Actually, either form will produce the exact same run-time behavior:
a literal constant of type TEXT is fed to the function nextval(text),
which returns an int4 (or an int8 on 7.2 and later).

The reason pg_dump emits the ::text cast is that it's being paranoid
about making sure that the reloaded dump will be interpreted exactly
the same way.  For example, if we had both nextval(text) and
nextval(varchar) then an explicit cast would be essential to ensure that
the same one is chosen next time.  (We don't have multiple versions of
nextval, but there are other functions and operators where this exact
scenario arises.  Also, pg_dump is trying to cover its rear in case new
functions get added in future releases, possibly creating a choice of
interpretations where none exists today.)

            regards, tom lane



pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: how to view table foreign keys/triggers?
Next
From: Henk Schets
Date:
Subject: sequences what does ::text mean ?