Re: SELECT CAST(123 AS char) -> 1

Поиск
Список
Период
Сортировка
Искать
От
Dean Gibson (DB Administrator)
Тема
Re: SELECT CAST(123 AS char) -> 1
Дата
Msg-id
47B1EAA5.8060203@ultimeth.com
Ответ на
Список
Дерево обсуждения
SELECT CAST(123 AS char) -> 1 Ken Johanson <pg-user@kensystem.com>
Re: SELECT CAST(123 AS char) -> 1 Tom Lane <tgl@sss.pgh.pa.us>
Re: SELECT CAST(123 AS char) -> 1 Stephan Szabo <sszabo@megazone.bigpanda.com>
Re: SELECT CAST(123 AS char) -> 1 Tom Lane <tgl@sss.pgh.pa.us>
Re: SELECT CAST(123 AS char) -> 1 Stephan Szabo <sszabo@megazone.bigpanda.com>
Re: SELECT CAST(123 AS char) -> 1 Ken Johanson <pg-user@kensystem.com>
Re: SELECT CAST(123 AS char) -> 1 Tom Lane <tgl@sss.pgh.pa.us>
Re: SELECT CAST(123 AS char) -> 1 Stephan Szabo <sszabo@megazone.bigpanda.com>
Re: SELECT CAST(123 AS char) -> 1 Ken Johanson <pg-user@kensystem.com>
Re: SELECT CAST(123 AS char) -> 1 Gregory Stark <stark@enterprisedb.com>
Re: SELECT CAST(123 AS char) -> 1 Ken Johanson <pg-user@kensystem.com>
Re: SELECT CAST(123 AS char) -> 1 "Dean Gibson (DB Administrator)" <postgresql@ultimeth.com>
Re: SELECT CAST(123 AS char) -> 1 Ken Johanson <pg-user@kensystem.com>
Re: SELECT CAST(123 AS char) -> 1 "Dean Gibson (DB Administrator)" <postgresql@ultimeth.com>
Re: SELECT CAST(123 AS char) -> 1 Ken Johanson <pg-user@kensystem.com>
Re: SELECT CAST(123 AS char) -> 1 Andrew Sullivan <ajs@crankycanuck.ca>
Re: SELECT CAST(123 AS char) -> 1 Ken Johanson <pg-user@kensystem.com>
Re: SELECT CAST(123 AS char) -> 1 Alvaro Herrera <alvherre@commandprompt.com>
Re: SELECT CAST(123 AS char) -> 1 Ken Johanson <pg-user@kensystem.com>
Re: SELECT CAST(123 AS char) -> 1 Alvaro Herrera <alvherre@commandprompt.com>
Re: SELECT CAST(123 AS char) -> 1 Richard Huxton <dev@archonet.com>
Re: SELECT CAST(123 AS char) -> 1 Tom Lane <tgl@sss.pgh.pa.us>
Re: SELECT CAST(123 AS char) -> 1 Richard Huxton <dev@archonet.com>
Re: SELECT CAST(123 AS char) -> 1 Ken Johanson <pg-user@kensystem.com>
Re: SELECT CAST(123 AS char) -> 1 "Dean Gibson (DB Administrator)" <postgresql@ultimeth.com>
Re: SELECT CAST(123 AS char) -> 1 Ken Johanson <pg-user@kensystem.com>
Re: SELECT CAST(123 AS char) -> 1 Tom Lane <tgl@sss.pgh.pa.us>
Re: SELECT CAST(123 AS char) -> 1 Ken Johanson <pg-user@kensystem.com>
Re: SELECT CAST(123 AS char) -> 1 Martijn van Oosterhout <kleptog@svana.org>
On 2008-02-12 07:30, Ken Johanson wrote:

Sure, but you're a prime candidate for understanding the value of following the spec if you're trying to write software that works with multiple databases.

The spec has diminished in this (CAST without length) context:
a) following it produces an output which has no usefulness whatsoever (123 != 1)
I OFTEN use a cast of CHAR to get just the first character.

b) all the other databases chose to not follow the spec in the context of cast and char with implicit length.

I doubt that:

http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db2.doc.sqlref/castsp.htm
http://msdn2.microsoft.com/en-us/library/aa258242(SQL.80).aspx

Your specific example is covered here:
http://vista.intersystems.com/csp/docbook/DocBook.UI.Page.cls?KEY=RSQL_cast

and here:
http://answers.yahoo.com/question/index?qid=20071017084134AA4mCJC


When the length is unqualified, a cast to char should one of:

1) failfast
2) auto-size to char-count (de facto)
3) pad to the max-length

What is wrong with using VARCHAR for your purpose????????????????????????????  If you want the string auto-sized, that is what VARCHAR is for.

CHAR is, BY DEFINITION, a DECLARED fixed length.


В списке pgsql-general по дате отправления
От: Lew
Дата:
От: Alvaro Herrera
Дата:
FAQ