pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
empty string casting to typed value 3+ messages / 3 participants [nested] [flat]
* empty string casting to typed value @ 2004-06-07 06:37 sad <sad@bankir.ru> 2004-06-07 13:59 ` Re: empty string casting to typed value Bruno Wolff III <bruno@wolff.to> 2004-06-07 14:34 ` Re: empty string casting to typed value Stephan Szabo <sszabo@megazone.bigpanda.com> 0 siblings, 2 replies; 3+ messages in thread From: sad @ 2004-06-07 06:37 UTC (permalink / raw) To: pgsql-sql Hello It is clear that '' is a bad integer or timestamp representation but during the user input NULLs are usually represented with empty strings sometimes bunch of 'if empty' instructions grows huge (and in case of casting to timestamp apostrophes make sense) Why you prohibit casting ''::int to NULL ? What would you advice ? thnx ^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: empty string casting to typed value 2004-06-07 06:37 empty string casting to typed value sad <sad@bankir.ru> @ 2004-06-07 13:59 ` Bruno Wolff III <bruno@wolff.to> 1 sibling, 0 replies; 3+ messages in thread From: Bruno Wolff III @ 2004-06-07 13:59 UTC (permalink / raw) To: sad <sad@bankir.ru>; +Cc: pgsql-sql On Mon, Jun 07, 2004 at 10:37:44 +0400, sad <sad@bankir.ru> wrote: > Hello > > It is clear that '' is a bad integer or timestamp representation > > but during the user input NULLs are usually represented with empty strings > sometimes bunch of 'if empty' instructions grows huge > (and in case of casting to timestamp apostrophes make sense) An empty string is not an obvious particular time. Different applications might treat this differently. Not applicable, missing, and current time are all reasonable defaults. > > Why you prohibit casting ''::int to NULL ? > What would you advice ? The application should handle mapping appropiate inputs to NULL or perhaps DEFAULT. ^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: empty string casting to typed value 2004-06-07 06:37 empty string casting to typed value sad <sad@bankir.ru> @ 2004-06-07 14:34 ` Stephan Szabo <sszabo@megazone.bigpanda.com> 1 sibling, 0 replies; 3+ messages in thread From: Stephan Szabo @ 2004-06-07 14:34 UTC (permalink / raw) To: sad <sad@bankir.ru>; +Cc: pgsql-sql On Mon, 7 Jun 2004, sad wrote: > It is clear that '' is a bad integer or timestamp representation > > but during the user input NULLs are usually represented with empty strings > sometimes bunch of 'if empty' instructions grows huge > (and in case of casting to timestamp apostrophes make sense) > Why you prohibit casting ''::int to NULL ? In part, this is for spec complience. The spec pretty explicitly says that casting something that does not look like a signed numeric literal to a numeric type results in an error and empty string does not look like a signed numeric literal. In part, it is for the fact that doing such conversions opens the doors to alot of odd behavior depending on how it is defined. For example, if the cast that effectively happens on insert is allowed to do that conversion, a phrase like VALUES ('', '', '') may insert 0-3 nulls into a table depending on the datatypes since ''=>NULL shouldn't happen for character types. If it's allowed to happen on implicit casts in expressions, a phrase like WHERE col != '' may silently be written into something meaningless (col != NULL) for some types. Even when limited to explicit casts only, it blurs the line with non-NULL values and will make people confused when it doesn't occur for character types. Finally, you should be able to write functions that take a text argument and return an integer, datetype, whatever that return NULL for empty string and the value cast to integer for others so there's probably not much reason to break the cast semantics. ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2004-06-07 14:34 UTC | newest] Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2004-06-07 06:37 empty string casting to typed value sad <sad@bankir.ru> 2004-06-07 13:59 ` Bruno Wolff III <bruno@wolff.to> 2004-06-07 14:34 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox