Skip site navigation (1) Skip section navigation (2)

Re: Smallint needs explicit cast in psql?

From: Matt Musgrove <MMusgrove(at)efji(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>, Judy Loomis<JLoomis(at)efji(dot)com>
Subject: Re: Smallint needs explicit cast in psql?
Date: 2012-07-17 15:57:40
Message-ID: C0FE28B9352B6F4F8CE371643EC3B251210877DE@EFJDFWMB01.EFJDFW.local (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> Right, because assigning to a table column is an "assignment" cast --- 
> which has more liberal rules, because either you can coerce the value 
> to the table column's type or you're going to fail anyway.  So the 
> system will take the integer literal and try to downcast to smallint, 
> and if that doesn't work then the query was doomed anyhow.

This one sank in last night when I re-read the docs for CREATE CAST.

> Coercion of a value to match a function argument is a different matter;
> the system will not choose a coercion that is "surprising" in any way 
> or has the potential to fail due to issues such as range limitations.
> The reason for the difference in behavior is probably not very obvious 
> when you have only one possible function to match, but we need this 
> restriction in order for things to behave sanely with overloaded 
> functions (or operators).  The text in chapter 10 expands on that a 
> bit.

This is exactly what was confusing us; we aren't using function overloading so at the time it seemed like it should just work. I think I finally understand it again re-reading chapter 10 again.


In response to

pgsql-novice by date

Next:From: Ioannis AnagnostopoulosDate: 2012-07-19 12:24:34
Subject: Re: Index slow down insertions...
Previous:From: Rob RichardsonDate: 2012-07-17 15:12:59
Subject: Re: How do I convert four table columns into a box?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group