From: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Cc: | Daniel Schuchardt <daniel_schuchardt(at)web(dot)de> |
Subject: | Re: now i'm really confused. insert/update does autocast, where sometimes. |
Date: | 2008-05-08 15:26:17 |
Message-ID: | 200805081726.17959.peter_e@gmx.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Am Dienstag, 6. Mai 2008 schrieb Daniel Schuchardt:
> so it depends on ? if i need an explicit cast?
A type cast can be attempted in three different contexts (see also CREATE CAST
reference page):
- implicitly
- storage assignment
- explicitly
The explicit case is if you call CAST() or ::. This is always allowed if an
appropriate cast routine is defined.
The implicit case is if an operator or function requires type A and the
expression is of type B. This cast is only performed if the cast routine is
defined and allowed for the implicit context. The change in 8.3 was
to "downgrade" many casting functions from implicit to assignment or
explicit.
The storage assignment case is if the value has type A and is about to be
stored into a column of type B. This is allowed if the cast routine is
allowed for the assignment context. This is, perhaps surprisingly, a
separate level between implicit and explicit casts. So in reference to your
subject line, yes, INSERT and UPDATE do have different casting behavior than
SELECT. (This is not really accurate, because the WHERE clause of an UPDATE
would follow the same rules as a WHERE clause in SELECT. The assignment
context only applies for values that are really going to be stored.)
This is all in line with the SQL standard.
From | Date | Subject | |
---|---|---|---|
Next Message | Shane Ambler | 2008-05-08 16:02:58 | Re: Problems with memory |
Previous Message | John Gateley | 2008-05-08 15:04:20 | Re: auto-vacuum questions |