Thread: sequences what does ::text mean ?
Hi, In a table I have as a default value nextval('seq_auteurs'). What's the difference with nextval('seq_auteurs'::text) ? Henk
Henk Schets wrote: >Hi, > >In a table I have as a default value nextval('seq_auteurs'). What's the difference with nextval('seq_auteurs'::text) ? > >Henk > > > >---------------------------(end of broadcast)--------------------------- >TIP 4: Don't 'kill -9' the postmaster > > > > > The difference ist nextval('seq_autheurs') you get an integer back and with the second one it casts the integer to text and returns a text value Ewald
On Wed, 2002-07-03 at 11:05, Ewald Geschwinde wrote: > Henk Schets wrote: > >In a table I have as a default value nextval('seq_auteurs'). What's the difference with nextval('seq_auteurs'::text) ? > The difference ist nextval('seq_autheurs') you get an integer back and > with the second one it casts the integer to text and returns a text value That would be "nextval('seq_auteurs')::text", with the cast outside the parentheses. "nextval('seq_auteurs'::text)" converts 'seq_auteurs' to text before using it to identify the sequence for nextval(). Since 'seq_auteurs' is already text, this is a null operation. Oliver
On Wed, 2002-07-03 at 22:05, Ewald Geschwinde wrote: > Henk Schets wrote: > > >Hi, > > > >In a table I have as a default value nextval('seq_auteurs'). What's the difference with nextval('seq_auteurs'::text)? > > > >Henk > > > > > > > >---------------------------(end of broadcast)--------------------------- > >TIP 4: Don't 'kill -9' the postmaster > > > > > > > > > > > The difference ist nextval('seq_autheurs') you get an integer back and > with the second one it casts the integer to text and returns a text value No you won't - that ::text is _inside_ the brackets. You'll still get an INT4. There really is no difference. I think the second might be the somewhat pedantic output of pg_dump. Regards, Andrew. -- -------------------------------------------------------------------- Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington WEB: http://catalyst.net.nz/ PHYS: Level 2, 150-154 Willis St DDI: +64(4)916-7201 MOB: +64(21)635-694 OFFICE: +64(4)499-2267 Are you enrolled at http://schoolreunions.co.nz/ yet?
See and here thought that if you can specify a datatype then you circumvent a type resolution or two. 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. Joshua b. Jore ; http://www.greentechnologist.org On 3 Jul 2002, Andrew McMillan wrote: > On Wed, 2002-07-03 at 22:05, Ewald Geschwinde wrote: > > Henk Schets wrote: > > > > >Hi, > > > > > >In a table I have as a default value nextval('seq_auteurs'). What's the difference with nextval('seq_auteurs'::text)? > > > > > >Henk > > > > > > > > > > > >---------------------------(end of broadcast)--------------------------- > > >TIP 4: Don't 'kill -9' the postmaster > > > > > > > > > > > > > > > > > The difference ist nextval('seq_autheurs') you get an integer back and > > with the second one it casts the integer to text and returns a text value > > No you won't - that ::text is _inside_ the brackets. You'll still get > an INT4. > > There really is no difference. I think the second might be the somewhat > pedantic output of pg_dump. > > Regards, > Andrew. > -- > -------------------------------------------------------------------- > Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington > WEB: http://catalyst.net.nz/ PHYS: Level 2, 150-154 Willis St > DDI: +64(4)916-7201 MOB: +64(21)635-694 OFFICE: +64(4)499-2267 > Are you enrolled at http://schoolreunions.co.nz/ yet? > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly > > >
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
Ah so. Thanks for the clarification. Joshua b. Jore ; http://www.greentechnologist.org On Wed, 3 Jul 2002, Tom Lane wrote: > 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). > regards, tom lane