Обсуждение: [JDBC] JDBC String to Bool spec

Поиск
Список
Период
Сортировка

[JDBC] JDBC String to Bool spec

От
Kevin Wooten
Дата:
Does anybody know where in the specification it details the required/acceptable conversions from string values to
boolean? I cannot seem to find it in the PDF for 4.2. 

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a
text/varcharcolumn with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to
decodingthe column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!=
0”would also be valid, but vastly different. 

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as
ofyet. 

Re: JDBC String to Bool spec

От
Dave Cramer
Дата:


On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc

Re: [JDBC] JDBC String to Bool spec

От
Dave Cramer
Дата:


On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc

Re: JDBC String to Bool spec

От
Kevin Wooten
Дата:
Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc


Re: [JDBC] JDBC String to Bool spec

От
Kevin Wooten
Дата:
Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc


Re: [JDBC] JDBC String to Bool spec

От
Kevin Wooten
Дата:
Actually this table isn’t what I’m looking for.  Related to example I provided below, there doesn’t seem to be a list of “acceptable values” when converting a string to a boolean; only that “getBoolean” must support conversion from VARCHAR/CHAR.


On Jan 15, 2017, at 4:29 PM, Kevin Wooten <kdubb@me.com> wrote:

Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



Re: JDBC String to Bool spec

От
Kevin Wooten
Дата:
Actually this table isn’t what I’m looking for.  Related to example I provided below, there doesn’t seem to be a list of “acceptable values” when converting a string to a boolean; only that “getBoolean” must support conversion from VARCHAR/CHAR.


On Jan 15, 2017, at 4:29 PM, Kevin Wooten <kdubb@me.com> wrote:

Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



Re: JDBC String to Bool spec

От
Dave Cramer
Дата:

On 15 January 2017 at 18:33, Kevin Wooten <kdubb@me.com> wrote:
Actually this table isn’t what I’m looking for.  Related to example I provided below, there doesn’t seem to be a list of “acceptable values” when converting a string to a boolean; only that “getBoolean” must support conversion from VARCHAR/CHAR.



Ya I thought you were looking for something else. Not sure how you deal with your exact use case



 
On Jan 15, 2017, at 4:29 PM, Kevin Wooten <kdubb@me.com> wrote:

Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc




Re: [JDBC] JDBC String to Bool spec

От
Dave Cramer
Дата:

On 15 January 2017 at 18:33, Kevin Wooten <kdubb@me.com> wrote:
Actually this table isn’t what I’m looking for.  Related to example I provided below, there doesn’t seem to be a list of “acceptable values” when converting a string to a boolean; only that “getBoolean” must support conversion from VARCHAR/CHAR.



Ya I thought you were looking for something else. Not sure how you deal with your exact use case



 
On Jan 15, 2017, at 4:29 PM, Kevin Wooten <kdubb@me.com> wrote:

Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc




Re: JDBC String to Bool spec

От
Kevin Wooten
Дата:
It’s not my use case.  It seems to me the driver should either support JDBC/Java conversions (true/yes => true, everything else false) or Postgres conversions (true/on/t/1 => true, false/off/f/0 => false, everything else error).  

Currently it seems theres a hodgepodge of supported conversion not really defined by the spec or server support; unless they are defined somewhere that I’m not aware off.

On Jan 15, 2017, at 4:42 PM, Dave Cramer <pg@fastcrypt.com> wrote:


On 15 January 2017 at 18:33, Kevin Wooten <kdubb@me.com> wrote:
Actually this table isn’t what I’m looking for.  Related to example I provided below, there doesn’t seem to be a list of “acceptable values” when converting a string to a boolean; only that “getBoolean” must support conversion from VARCHAR/CHAR.



Ya I thought you were looking for something else. Not sure how you deal with your exact use case



 
On Jan 15, 2017, at 4:29 PM, Kevin Wooten <kdubb@me.com> wrote:

Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc





Re: [JDBC] JDBC String to Bool spec

От
Kevin Wooten
Дата:
It’s not my use case.  It seems to me the driver should either support JDBC/Java conversions (true/yes => true, everything else false) or Postgres conversions (true/on/t/1 => true, false/off/f/0 => false, everything else error).  

Currently it seems theres a hodgepodge of supported conversion not really defined by the spec or server support; unless they are defined somewhere that I’m not aware off.

On Jan 15, 2017, at 4:42 PM, Dave Cramer <pg@fastcrypt.com> wrote:


On 15 January 2017 at 18:33, Kevin Wooten <kdubb@me.com> wrote:
Actually this table isn’t what I’m looking for.  Related to example I provided below, there doesn’t seem to be a list of “acceptable values” when converting a string to a boolean; only that “getBoolean” must support conversion from VARCHAR/CHAR.



Ya I thought you were looking for something else. Not sure how you deal with your exact use case



 
On Jan 15, 2017, at 4:29 PM, Kevin Wooten <kdubb@me.com> wrote:

Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc





Re: JDBC String to Bool spec

От
Jorge Solórzano
Дата:
Maybe we should support postgres conversion (https://www.postgresql.org/docs/current/static/datatype-boolean.html), similar to what is already on PgPreparedStatement and setObject.

Can you please open an issue on github to keep track of it?

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 5:54 PM, Kevin Wooten <kdubb@me.com> wrote:
It’s not my use case.  It seems to me the driver should either support JDBC/Java conversions (true/yes => true, everything else false) or Postgres conversions (true/on/t/1 => true, false/off/f/0 => false, everything else error).  

Currently it seems theres a hodgepodge of supported conversion not really defined by the spec or server support; unless they are defined somewhere that I’m not aware off.

On Jan 15, 2017, at 4:42 PM, Dave Cramer <pg@fastcrypt.com> wrote:


On 15 January 2017 at 18:33, Kevin Wooten <kdubb@me.com> wrote:
Actually this table isn’t what I’m looking for.  Related to example I provided below, there doesn’t seem to be a list of “acceptable values” when converting a string to a boolean; only that “getBoolean” must support conversion from VARCHAR/CHAR.



Ya I thought you were looking for something else. Not sure how you deal with your exact use case



 
On Jan 15, 2017, at 4:29 PM, Kevin Wooten <kdubb@me.com> wrote:

Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc






Re: [JDBC] JDBC String to Bool spec

От
Jorge Solórzano
Дата:
Maybe we should support postgres conversion (https://www.postgresql.org/docs/current/static/datatype-boolean.html), similar to what is already on PgPreparedStatement and setObject.

Can you please open an issue on github to keep track of it?

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 5:54 PM, Kevin Wooten <kdubb@me.com> wrote:
It’s not my use case.  It seems to me the driver should either support JDBC/Java conversions (true/yes => true, everything else false) or Postgres conversions (true/on/t/1 => true, false/off/f/0 => false, everything else error).  

Currently it seems theres a hodgepodge of supported conversion not really defined by the spec or server support; unless they are defined somewhere that I’m not aware off.

On Jan 15, 2017, at 4:42 PM, Dave Cramer <pg@fastcrypt.com> wrote:


On 15 January 2017 at 18:33, Kevin Wooten <kdubb@me.com> wrote:
Actually this table isn’t what I’m looking for.  Related to example I provided below, there doesn’t seem to be a list of “acceptable values” when converting a string to a boolean; only that “getBoolean” must support conversion from VARCHAR/CHAR.



Ya I thought you were looking for something else. Not sure how you deal with your exact use case



 
On Jan 15, 2017, at 4:29 PM, Kevin Wooten <kdubb@me.com> wrote:

Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc






Re: JDBC String to Bool spec

От
Jorge Solórzano
Дата:
BTW, the JDBC specs (or at least the javadocs) reads this:

If the designated column has a datatype of CHAR or VARCHAR and contains a "0" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 0, a value of false is returned. If the designated column has a datatype of CHAR or VARCHAR and contains a "1" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 1, a value of true is returned.

So this use case is already covered, but I think that having full postgres conversion is a better approach.
 

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 6:59 PM, Jorge Solórzano <jorsol@gmail.com> wrote:
Maybe we should support postgres conversion (https://www.postgresql.org/docs/current/static/datatype-boolean.html), similar to what is already on PgPreparedStatement and setObject.

Can you please open an issue on github to keep track of it?

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 5:54 PM, Kevin Wooten <kdubb@me.com> wrote:
It’s not my use case.  It seems to me the driver should either support JDBC/Java conversions (true/yes => true, everything else false) or Postgres conversions (true/on/t/1 => true, false/off/f/0 => false, everything else error).  

Currently it seems theres a hodgepodge of supported conversion not really defined by the spec or server support; unless they are defined somewhere that I’m not aware off.

On Jan 15, 2017, at 4:42 PM, Dave Cramer <pg@fastcrypt.com> wrote:


On 15 January 2017 at 18:33, Kevin Wooten <kdubb@me.com> wrote:
Actually this table isn’t what I’m looking for.  Related to example I provided below, there doesn’t seem to be a list of “acceptable values” when converting a string to a boolean; only that “getBoolean” must support conversion from VARCHAR/CHAR.



Ya I thought you were looking for something else. Not sure how you deal with your exact use case



 
On Jan 15, 2017, at 4:29 PM, Kevin Wooten <kdubb@me.com> wrote:

Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc







Re: [JDBC] JDBC String to Bool spec

От
Jorge Solórzano
Дата:
BTW, the JDBC specs (or at least the javadocs) reads this:

If the designated column has a datatype of CHAR or VARCHAR and contains a "0" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 0, a value of false is returned. If the designated column has a datatype of CHAR or VARCHAR and contains a "1" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 1, a value of true is returned.

So this use case is already covered, but I think that having full postgres conversion is a better approach.
 

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 6:59 PM, Jorge Solórzano <jorsol@gmail.com> wrote:
Maybe we should support postgres conversion (https://www.postgresql.org/docs/current/static/datatype-boolean.html), similar to what is already on PgPreparedStatement and setObject.

Can you please open an issue on github to keep track of it?

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 5:54 PM, Kevin Wooten <kdubb@me.com> wrote:
It’s not my use case.  It seems to me the driver should either support JDBC/Java conversions (true/yes => true, everything else false) or Postgres conversions (true/on/t/1 => true, false/off/f/0 => false, everything else error).  

Currently it seems theres a hodgepodge of supported conversion not really defined by the spec or server support; unless they are defined somewhere that I’m not aware off.

On Jan 15, 2017, at 4:42 PM, Dave Cramer <pg@fastcrypt.com> wrote:


On 15 January 2017 at 18:33, Kevin Wooten <kdubb@me.com> wrote:
Actually this table isn’t what I’m looking for.  Related to example I provided below, there doesn’t seem to be a list of “acceptable values” when converting a string to a boolean; only that “getBoolean” must support conversion from VARCHAR/CHAR.



Ya I thought you were looking for something else. Not sure how you deal with your exact use case



 
On Jan 15, 2017, at 4:29 PM, Kevin Wooten <kdubb@me.com> wrote:

Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc







Re: [JDBC] JDBC String to Bool spec

От
Kevin Wooten
Дата:
Good find on this text. That’s what I couldn’t seem to find in the spec. 

Yes these cases are covered… but so are many other cases outside the JDBC spec; some that even Postgres itself doesn’t support.  That’s kind of what I’m getting at.  It seems that currently we’re just attempting to “convert everything” and I’m not sure that’s the appropriate approach when implementing a strict spec like JDBC.

Also, the current conversion set isn’t normalized at all. When all else fails the  “string -> boolean” conversion code then attempts a “string -> double” conversion and if that succeeds it then tests against “1.0” for true and everything else false.  JDBC does seem to give at least some guidance here, suggesting that it should be a strict “1.0 -> true” or “0.0 -> false” mapping as is implemented for “1 -> true” or “0 -> false”.  

I will reiterate that Postgres doesn’t support anything of the sort.  It has a strict set of true and strict set of false values when converting from “string -> bool” anything else results in an error. Although, it does support more values than outlined in the text quoted below.


On Jan 15, 2017, at 6:14 PM, Jorge Solórzano <jorsol@gmail.com> wrote:

BTW, the JDBC specs (or at least the javadocs) reads this:

If the designated column has a datatype of CHAR or VARCHAR and contains a "0" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 0, a value of false is returned. If the designated column has a datatype of CHAR or VARCHAR and contains a "1" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 1, a value of true is returned.

So this use case is already covered, but I think that having full postgres conversion is a better approach.
 

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 6:59 PM, Jorge Solórzano <jorsol@gmail.com> wrote:
Maybe we should support postgres conversion (https://www.postgresql.org/docs/current/static/datatype-boolean.html), similar to what is already on PgPreparedStatement and setObject.

Can you please open an issue on github to keep track of it?

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 5:54 PM, Kevin Wooten <kdubb@me.com> wrote:
It’s not my use case.  It seems to me the driver should either support JDBC/Java conversions (true/yes => true, everything else false) or Postgres conversions (true/on/t/1 => true, false/off/f/0 => false, everything else error).  

Currently it seems theres a hodgepodge of supported conversion not really defined by the spec or server support; unless they are defined somewhere that I’m not aware off.

On Jan 15, 2017, at 4:42 PM, Dave Cramer <pg@fastcrypt.com> wrote:


On 15 January 2017 at 18:33, Kevin Wooten <kdubb@me.com> wrote:
Actually this table isn’t what I’m looking for.  Related to example I provided below, there doesn’t seem to be a list of “acceptable values” when converting a string to a boolean; only that “getBoolean” must support conversion from VARCHAR/CHAR.



Ya I thought you were looking for something else. Not sure how you deal with your exact use case



 
On Jan 15, 2017, at 4:29 PM, Kevin Wooten <kdubb@me.com> wrote:

Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc








Re: JDBC String to Bool spec

От
Kevin Wooten
Дата:
Good find on this text. That’s what I couldn’t seem to find in the spec. 

Yes these cases are covered… but so are many other cases outside the JDBC spec; some that even Postgres itself doesn’t support.  That’s kind of what I’m getting at.  It seems that currently we’re just attempting to “convert everything” and I’m not sure that’s the appropriate approach when implementing a strict spec like JDBC.

Also, the current conversion set isn’t normalized at all. When all else fails the  “string -> boolean” conversion code then attempts a “string -> double” conversion and if that succeeds it then tests against “1.0” for true and everything else false.  JDBC does seem to give at least some guidance here, suggesting that it should be a strict “1.0 -> true” or “0.0 -> false” mapping as is implemented for “1 -> true” or “0 -> false”.  

I will reiterate that Postgres doesn’t support anything of the sort.  It has a strict set of true and strict set of false values when converting from “string -> bool” anything else results in an error. Although, it does support more values than outlined in the text quoted below.


On Jan 15, 2017, at 6:14 PM, Jorge Solórzano <jorsol@gmail.com> wrote:

BTW, the JDBC specs (or at least the javadocs) reads this:

If the designated column has a datatype of CHAR or VARCHAR and contains a "0" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 0, a value of false is returned. If the designated column has a datatype of CHAR or VARCHAR and contains a "1" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 1, a value of true is returned.

So this use case is already covered, but I think that having full postgres conversion is a better approach.
 

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 6:59 PM, Jorge Solórzano <jorsol@gmail.com> wrote:
Maybe we should support postgres conversion (https://www.postgresql.org/docs/current/static/datatype-boolean.html), similar to what is already on PgPreparedStatement and setObject.

Can you please open an issue on github to keep track of it?

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 5:54 PM, Kevin Wooten <kdubb@me.com> wrote:
It’s not my use case.  It seems to me the driver should either support JDBC/Java conversions (true/yes => true, everything else false) or Postgres conversions (true/on/t/1 => true, false/off/f/0 => false, everything else error).  

Currently it seems theres a hodgepodge of supported conversion not really defined by the spec or server support; unless they are defined somewhere that I’m not aware off.

On Jan 15, 2017, at 4:42 PM, Dave Cramer <pg@fastcrypt.com> wrote:


On 15 January 2017 at 18:33, Kevin Wooten <kdubb@me.com> wrote:
Actually this table isn’t what I’m looking for.  Related to example I provided below, there doesn’t seem to be a list of “acceptable values” when converting a string to a boolean; only that “getBoolean” must support conversion from VARCHAR/CHAR.



Ya I thought you were looking for something else. Not sure how you deal with your exact use case



 
On Jan 15, 2017, at 4:29 PM, Kevin Wooten <kdubb@me.com> wrote:

Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc








Re: JDBC String to Bool spec

От
Mark Rotteveel
Дата:
On 2017-01-16 00:20, Kevin Wooten wrote:
> Does anybody know where in the specification it details the
> required/acceptable conversions from string values to boolean?  I
> cannot seem to find it in the PDF for 4.2.
>
> I am curious about some of the conversions that are done.  For
> example, calling “ResultSet.getBoolean” on a text/varchar column with
> the value “1.0”.  This conversion succeeds because the driver (both
> pgjdbc & ng) fallback to decoding the column as a double then
> converting that by testing it “== 1”; which seems valid but
> questionable since “!= 0” would also be valid, but vastly different.
>
> This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in
> an error) and I cannot find anything in JDBC as of yet.

As far as I know the JDBC spec defers to the SQL standard specification
for this. Unfortunately I don't have a copy handy to check how the SQL
standard defines it.

Mark


Re: [JDBC] JDBC String to Bool spec

От
Mark Rotteveel
Дата:
On 2017-01-16 00:20, Kevin Wooten wrote:
> Does anybody know where in the specification it details the
> required/acceptable conversions from string values to boolean?  I
> cannot seem to find it in the PDF for 4.2.
>
> I am curious about some of the conversions that are done.  For
> example, calling “ResultSet.getBoolean” on a text/varchar column with
> the value “1.0”.  This conversion succeeds because the driver (both
> pgjdbc & ng) fallback to decoding the column as a double then
> converting that by testing it “== 1”; which seems valid but
> questionable since “!= 0” would also be valid, but vastly different.
>
> This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in
> an error) and I cannot find anything in JDBC as of yet.

As far as I know the JDBC spec defers to the SQL standard specification
for this. Unfortunately I don't have a copy handy to check how the SQL
standard defines it.

Mark


Re: [JDBC] JDBC String to Bool spec

От
Thomas Kellerer
Дата:
Mark Rotteveel schrieb am 16.01.2017 um 09:37:
> As far as I know the JDBC spec defers to the SQL standard
> specification for this. Unfortunately I don't have a copy handy to
> check how the SQL standard defines it.


    <boolean value expression> ::=
        <boolean term>
      | <boolean value expression> OR <boolean term>

    <boolean term> ::=
        <boolean factor>
      | <boolean term> AND <boolean factor>

    <boolean factor> ::=
      [ NOT ] <boolean test>

    <boolean test> ::=
      <boolean primary> [ IS [ NOT ] <truth value> ]

    <truth value> ::=
      TRUE
      | FALSE
      | UNKNOWN

    <boolean primary> ::=
        <predicate>
      | <boolean predicand>

    <boolean predicand> ::=
        <parenthesized boolean value expression>
      | <nonparenthesized value expression primary>

    <parenthesized boolean value expression> ::=
      <left paren> <boolean value expression> <right paren>

so it boils down to

  <truth value> ::=
      TRUE
    | FALSE
    | UNKNOWN

as far as I can tell.


Re: JDBC String to Bool spec

От
Thomas Kellerer
Дата:
Mark Rotteveel schrieb am 16.01.2017 um 09:37:
> As far as I know the JDBC spec defers to the SQL standard
> specification for this. Unfortunately I don't have a copy handy to
> check how the SQL standard defines it.


    <boolean value expression> ::=
        <boolean term>
      | <boolean value expression> OR <boolean term>

    <boolean term> ::=
        <boolean factor>
      | <boolean term> AND <boolean factor>

    <boolean factor> ::=
      [ NOT ] <boolean test>

    <boolean test> ::=
      <boolean primary> [ IS [ NOT ] <truth value> ]

    <truth value> ::=
      TRUE
      | FALSE
      | UNKNOWN

    <boolean primary> ::=
        <predicate>
      | <boolean predicand>

    <boolean predicand> ::=
        <parenthesized boolean value expression>
      | <nonparenthesized value expression primary>

    <parenthesized boolean value expression> ::=
      <left paren> <boolean value expression> <right paren>

so it boils down to

  <truth value> ::=
      TRUE
    | FALSE
    | UNKNOWN

as far as I can tell.


Re: [JDBC] JDBC String to Bool spec

От
Mark Rotteveel
Дата:
On 2017-01-16 09:59, Thomas Kellerer wrote:
> Mark Rotteveel schrieb am 16.01.2017 um 09:37:
>> As far as I know the JDBC spec defers to the SQL standard
>> specification for this. Unfortunately I don't have a copy handy to
>> check how the SQL standard defines it.
>
>
>     <boolean value expression> ::=
>         <boolean term>
>       | <boolean value expression> OR <boolean term>
>
>     <boolean term> ::=
>         <boolean factor>
>       | <boolean term> AND <boolean factor>
>
>     <boolean factor> ::=
>       [ NOT ] <boolean test>
>
>     <boolean test> ::=
>       <boolean primary> [ IS [ NOT ] <truth value> ]
>
>     <truth value> ::=
>       TRUE
>       | FALSE
>       | UNKNOWN
>
>     <boolean primary> ::=
>         <predicate>
>       | <boolean predicand>
>
>     <boolean predicand> ::=
>         <parenthesized boolean value expression>
>       | <nonparenthesized value expression primary>
>
>     <parenthesized boolean value expression> ::=
>       <left paren> <boolean value expression> <right paren>
>
> so it boils down to
>
>   <truth value> ::=
>       TRUE
>     | FALSE
>     | UNKNOWN
>
> as far as I can tell.

IIRC, there is a section about conversion to boolean (maybe with CAST,
or maybe with the parameter specification), I'll try to find it when I
have access to a copy of the standard.

Mark


Re: JDBC String to Bool spec

От
Mark Rotteveel
Дата:
On 2017-01-16 09:59, Thomas Kellerer wrote:
> Mark Rotteveel schrieb am 16.01.2017 um 09:37:
>> As far as I know the JDBC spec defers to the SQL standard
>> specification for this. Unfortunately I don't have a copy handy to
>> check how the SQL standard defines it.
>
>
>     <boolean value expression> ::=
>         <boolean term>
>       | <boolean value expression> OR <boolean term>
>
>     <boolean term> ::=
>         <boolean factor>
>       | <boolean term> AND <boolean factor>
>
>     <boolean factor> ::=
>       [ NOT ] <boolean test>
>
>     <boolean test> ::=
>       <boolean primary> [ IS [ NOT ] <truth value> ]
>
>     <truth value> ::=
>       TRUE
>       | FALSE
>       | UNKNOWN
>
>     <boolean primary> ::=
>         <predicate>
>       | <boolean predicand>
>
>     <boolean predicand> ::=
>         <parenthesized boolean value expression>
>       | <nonparenthesized value expression primary>
>
>     <parenthesized boolean value expression> ::=
>       <left paren> <boolean value expression> <right paren>
>
> so it boils down to
>
>   <truth value> ::=
>       TRUE
>     | FALSE
>     | UNKNOWN
>
> as far as I can tell.

IIRC, there is a section about conversion to boolean (maybe with CAST,
or maybe with the parameter specification), I'll try to find it when I
have access to a copy of the standard.

Mark


Re: [JDBC] JDBC String to Bool spec

От
Jorge Solórzano
Дата:
I guess you are right, the driver currently blindly converts incorrect values to false, IMO it should accept only values allowed in postgresql server since this is the PgJBDC driver, but is should also support a cast of float, double and decimal as this is required by the jdbc spec.

@vlsi, @davecramer, what is your opinion about blindly convert incorrect values to false? Should the driver accept this kind of behaviour?

For instance something like this is allowed (and there is even a test for this):

CREATE TABLE testboolstring (a varchar(30));
INSERT INTO testboolstring VALUES('this is not true');

when execute rs.getBoolean(1), it gets false, but it should be an cannotCastException.



Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 7:25 PM, Kevin Wooten <kdubb@me.com> wrote:
Good find on this text. That’s what I couldn’t seem to find in the spec. 

Yes these cases are covered… but so are many other cases outside the JDBC spec; some that even Postgres itself doesn’t support.  That’s kind of what I’m getting at.  It seems that currently we’re just attempting to “convert everything” and I’m not sure that’s the appropriate approach when implementing a strict spec like JDBC.

Also, the current conversion set isn’t normalized at all. When all else fails the  “string -> boolean” conversion code then attempts a “string -> double” conversion and if that succeeds it then tests against “1.0” for true and everything else false.  JDBC does seem to give at least some guidance here, suggesting that it should be a strict “1.0 -> true” or “0.0 -> false” mapping as is implemented for “1 -> true” or “0 -> false”.  

I will reiterate that Postgres doesn’t support anything of the sort.  It has a strict set of true and strict set of false values when converting from “string -> bool” anything else results in an error. Although, it does support more values than outlined in the text quoted below.


On Jan 15, 2017, at 6:14 PM, Jorge Solórzano <jorsol@gmail.com> wrote:

BTW, the JDBC specs (or at least the javadocs) reads this:

If the designated column has a datatype of CHAR or VARCHAR and contains a "0" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 0, a value of false is returned. If the designated column has a datatype of CHAR or VARCHAR and contains a "1" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 1, a value of true is returned.

So this use case is already covered, but I think that having full postgres conversion is a better approach.
 

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 6:59 PM, Jorge Solórzano <jorsol@gmail.com> wrote:
Maybe we should support postgres conversion (https://www.postgresql.org/docs/current/static/datatype-boolean.html), similar to what is already on PgPreparedStatement and setObject.

Can you please open an issue on github to keep track of it?

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 5:54 PM, Kevin Wooten <kdubb@me.com> wrote:
It’s not my use case.  It seems to me the driver should either support JDBC/Java conversions (true/yes => true, everything else false) or Postgres conversions (true/on/t/1 => true, false/off/f/0 => false, everything else error).  

Currently it seems theres a hodgepodge of supported conversion not really defined by the spec or server support; unless they are defined somewhere that I’m not aware off.

On Jan 15, 2017, at 4:42 PM, Dave Cramer <pg@fastcrypt.com> wrote:


On 15 January 2017 at 18:33, Kevin Wooten <kdubb@me.com> wrote:
Actually this table isn’t what I’m looking for.  Related to example I provided below, there doesn’t seem to be a list of “acceptable values” when converting a string to a boolean; only that “getBoolean” must support conversion from VARCHAR/CHAR.



Ya I thought you were looking for something else. Not sure how you deal with your exact use case



 
On Jan 15, 2017, at 4:29 PM, Kevin Wooten <kdubb@me.com> wrote:

Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc









Re: JDBC String to Bool spec

От
Jorge Solórzano
Дата:
I guess you are right, the driver currently blindly converts incorrect values to false, IMO it should accept only values allowed in postgresql server since this is the PgJBDC driver, but is should also support a cast of float, double and decimal as this is required by the jdbc spec.

@vlsi, @davecramer, what is your opinion about blindly convert incorrect values to false? Should the driver accept this kind of behaviour?

For instance something like this is allowed (and there is even a test for this):

CREATE TABLE testboolstring (a varchar(30));
INSERT INTO testboolstring VALUES('this is not true');

when execute rs.getBoolean(1), it gets false, but it should be an cannotCastException.



Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 7:25 PM, Kevin Wooten <kdubb@me.com> wrote:
Good find on this text. That’s what I couldn’t seem to find in the spec. 

Yes these cases are covered… but so are many other cases outside the JDBC spec; some that even Postgres itself doesn’t support.  That’s kind of what I’m getting at.  It seems that currently we’re just attempting to “convert everything” and I’m not sure that’s the appropriate approach when implementing a strict spec like JDBC.

Also, the current conversion set isn’t normalized at all. When all else fails the  “string -> boolean” conversion code then attempts a “string -> double” conversion and if that succeeds it then tests against “1.0” for true and everything else false.  JDBC does seem to give at least some guidance here, suggesting that it should be a strict “1.0 -> true” or “0.0 -> false” mapping as is implemented for “1 -> true” or “0 -> false”.  

I will reiterate that Postgres doesn’t support anything of the sort.  It has a strict set of true and strict set of false values when converting from “string -> bool” anything else results in an error. Although, it does support more values than outlined in the text quoted below.


On Jan 15, 2017, at 6:14 PM, Jorge Solórzano <jorsol@gmail.com> wrote:

BTW, the JDBC specs (or at least the javadocs) reads this:

If the designated column has a datatype of CHAR or VARCHAR and contains a "0" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 0, a value of false is returned. If the designated column has a datatype of CHAR or VARCHAR and contains a "1" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 1, a value of true is returned.

So this use case is already covered, but I think that having full postgres conversion is a better approach.
 

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 6:59 PM, Jorge Solórzano <jorsol@gmail.com> wrote:
Maybe we should support postgres conversion (https://www.postgresql.org/docs/current/static/datatype-boolean.html), similar to what is already on PgPreparedStatement and setObject.

Can you please open an issue on github to keep track of it?

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 5:54 PM, Kevin Wooten <kdubb@me.com> wrote:
It’s not my use case.  It seems to me the driver should either support JDBC/Java conversions (true/yes => true, everything else false) or Postgres conversions (true/on/t/1 => true, false/off/f/0 => false, everything else error).  

Currently it seems theres a hodgepodge of supported conversion not really defined by the spec or server support; unless they are defined somewhere that I’m not aware off.

On Jan 15, 2017, at 4:42 PM, Dave Cramer <pg@fastcrypt.com> wrote:


On 15 January 2017 at 18:33, Kevin Wooten <kdubb@me.com> wrote:
Actually this table isn’t what I’m looking for.  Related to example I provided below, there doesn’t seem to be a list of “acceptable values” when converting a string to a boolean; only that “getBoolean” must support conversion from VARCHAR/CHAR.



Ya I thought you were looking for something else. Not sure how you deal with your exact use case



 
On Jan 15, 2017, at 4:29 PM, Kevin Wooten <kdubb@me.com> wrote:

Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc









Re: JDBC String to Bool spec

От
Mark Rotteveel
Дата:
On 2017-01-16 11:10, Mark Rotteveel wrote:
> IIRC, there is a section about conversion to boolean (maybe with CAST,
> or maybe with the parameter specification), I'll try to find it when I
> have access to a copy of the standard.

I have done some research:

JDBC 4.2 says about boolean:

"If the designated column has a datatype of CHAR or VARCHAR and contains
a "0" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and
contains a 0, a value of false is returned. If the designated column has
a datatype of CHAR or VARCHAR and contains a "1" or has a datatype of
BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 1, a value of
true is returned." (javadoc ResultSet.getBoolean)

"When the column value in the database is SQL NULL, it may be returned
to the Java
application as null, 0, or false, depending on the type of the column
value.
Column values that map to Java Object types are returned as a Java null;
those
that map to numeric types are returned as 0; those that map to a Java
boolean are
returned as false." (section 15.2.3.3)

SQL:2011 (6.13 <cast specification>:

A table in the syntax rules shows that cast only allows conversion from
character types to boolean (and boolean to boolean) and boolean to
character types, and - if supported - to user defined types and
reference types (following rules I haven't looked at).

"[if TD is fixed length character string]:
e) If SD is boolean, then
Case:
i) If SV is True and LTD is not less than 4, then TV is 'TRUE' extended
on the right by LTD–4 <space>s.
ii) If SV is False and LTD is not less than 5, then TV is 'FALSE'
extended on the right by LTD–5 <space>s.
iii) Otherwise, an exception condition is raised: data exception —
invalid character value for cast."

"[if TD is variable length character string]:
e) If SD is boolean, then
Case:
i) If SV is True and MLTD is not less than 4, then TV is 'TRUE'.
ii) If SV is False and MLTD is not less than 5, then TV is 'FALSE'.
iii) Otherwise, an exception condition is raised: data exception —
invalid character value for cast."

"20) If TD is boolean, then
Case:
a) If SD is character string, then SV is replaced by
TRIM ( BOTH ' ' FROM VE )
Case:
i) If the rules for <literal> in Subclause 5.3, “<literal>”, can be
applied to SV to determine a valid
value of the data type TD, then let TV be that value.
ii) Otherwise, an exception condition is raised: data exception —
invalid character value for cast.
b) If SD is boolean, then TV is SV."

TD: Target dataype, SD: Source dataype, VE: value expression of the cast
operand, SV: source value, is the value of VE, TV: target value, (M)LTD:
(max) length of TD

Valid values according to 5.3:
<boolean literal> ::=
TRUE
| FALSE
| UNKNOWN

In other words, JDBC allows a bit wider definition, probably to address
compatibility with database systems that do not support boolean data
types.

Mark


Re: [JDBC] JDBC String to Bool spec

От
Mark Rotteveel
Дата:
On 2017-01-16 11:10, Mark Rotteveel wrote:
> IIRC, there is a section about conversion to boolean (maybe with CAST,
> or maybe with the parameter specification), I'll try to find it when I
> have access to a copy of the standard.

I have done some research:

JDBC 4.2 says about boolean:

"If the designated column has a datatype of CHAR or VARCHAR and contains
a "0" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and
contains a 0, a value of false is returned. If the designated column has
a datatype of CHAR or VARCHAR and contains a "1" or has a datatype of
BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 1, a value of
true is returned." (javadoc ResultSet.getBoolean)

"When the column value in the database is SQL NULL, it may be returned
to the Java
application as null, 0, or false, depending on the type of the column
value.
Column values that map to Java Object types are returned as a Java null;
those
that map to numeric types are returned as 0; those that map to a Java
boolean are
returned as false." (section 15.2.3.3)

SQL:2011 (6.13 <cast specification>:

A table in the syntax rules shows that cast only allows conversion from
character types to boolean (and boolean to boolean) and boolean to
character types, and - if supported - to user defined types and
reference types (following rules I haven't looked at).

"[if TD is fixed length character string]:
e) If SD is boolean, then
Case:
i) If SV is True and LTD is not less than 4, then TV is 'TRUE' extended
on the right by LTD–4 <space>s.
ii) If SV is False and LTD is not less than 5, then TV is 'FALSE'
extended on the right by LTD–5 <space>s.
iii) Otherwise, an exception condition is raised: data exception —
invalid character value for cast."

"[if TD is variable length character string]:
e) If SD is boolean, then
Case:
i) If SV is True and MLTD is not less than 4, then TV is 'TRUE'.
ii) If SV is False and MLTD is not less than 5, then TV is 'FALSE'.
iii) Otherwise, an exception condition is raised: data exception —
invalid character value for cast."

"20) If TD is boolean, then
Case:
a) If SD is character string, then SV is replaced by
TRIM ( BOTH ' ' FROM VE )
Case:
i) If the rules for <literal> in Subclause 5.3, “<literal>”, can be
applied to SV to determine a valid
value of the data type TD, then let TV be that value.
ii) Otherwise, an exception condition is raised: data exception —
invalid character value for cast.
b) If SD is boolean, then TV is SV."

TD: Target dataype, SD: Source dataype, VE: value expression of the cast
operand, SV: source value, is the value of VE, TV: target value, (M)LTD:
(max) length of TD

Valid values according to 5.3:
<boolean literal> ::=
TRUE
| FALSE
| UNKNOWN

In other words, JDBC allows a bit wider definition, probably to address
compatibility with database systems that do not support boolean data
types.

Mark


Re: [JDBC] JDBC String to Bool spec

От
Vladimir Sitnikov
Дата:
>when execute rs.getBoolean(1), it gets false, but it should be an cannotCastException.

I'm not sure what is the ultimate right thing there (please forgive me I did not follow the thread), however I'm quite sure we cannot just break things "for no obvious reason".

Of course, major version change like 9.4 -> 42.0 allows us to break things, however I'm not fan of breaking too much at the same time.

Just in case: java.lang.Boolean#valueOf(java.lang.String) does not throw on bad input.

Vladimir

Re: JDBC String to Bool spec

От
Vladimir Sitnikov
Дата:
>when execute rs.getBoolean(1), it gets false, but it should be an cannotCastException.

I'm not sure what is the ultimate right thing there (please forgive me I did not follow the thread), however I'm quite sure we cannot just break things "for no obvious reason".

Of course, major version change like 9.4 -> 42.0 allows us to break things, however I'm not fan of breaking too much at the same time.

Just in case: java.lang.Boolean#valueOf(java.lang.String) does not throw on bad input.

Vladimir

Re: JDBC String to Bool spec

От
Mark Rotteveel
Дата:
On 2017-01-16 20:16, Jorge Solórzano wrote:
> I guess you are right, the driver currently blindly converts incorrect
> values to false, IMO it should accept only values allowed in
> postgresql server since this is the PgJBDC driver, but is should also
> support a cast of float, double and decimal as this is required by the
> jdbc spec.

Interestingly, the JDBC 4.2 specification documentation allows more
types than the apidoc (see my previous email for a quote of the apidoc).
I will see if I can get Lance Andersen to amend the apidoc.

The JDBC specification mentions conversion for: TINYINT, SMALLINT,
INTEGER, BIGINT, REAL, FLOAT, DOUBLE, DECIMAL, NUMERIC, BIT, BOOLEAN,
CHAR, VARCHAR, LONGVARCHAR (and vice versa), the apidoc doesn't mention
the fixed and floating point types. Presumably this was added because
you can also call getInt on a double, etc.

> @vlsi, @davecramer, what is your opinion about blindly convert
> incorrect values to false? Should the driver accept this kind of
> behaviour?
>
> For instance something like this is allowed (and there is even a test
> for this):
>
> CREATE TABLE testboolstring (a varchar(30));
> INSERT INTO testboolstring VALUES('this is not true');
>
> when execute rs.getBoolean(1), it gets false, but it should be an
> cannotCastException.

You're right, but the question is: will you break existing code if you
apply this change?

Mark


Re: [JDBC] JDBC String to Bool spec

От
Mark Rotteveel
Дата:
On 2017-01-16 20:16, Jorge Solórzano wrote:
> I guess you are right, the driver currently blindly converts incorrect
> values to false, IMO it should accept only values allowed in
> postgresql server since this is the PgJBDC driver, but is should also
> support a cast of float, double and decimal as this is required by the
> jdbc spec.

Interestingly, the JDBC 4.2 specification documentation allows more
types than the apidoc (see my previous email for a quote of the apidoc).
I will see if I can get Lance Andersen to amend the apidoc.

The JDBC specification mentions conversion for: TINYINT, SMALLINT,
INTEGER, BIGINT, REAL, FLOAT, DOUBLE, DECIMAL, NUMERIC, BIT, BOOLEAN,
CHAR, VARCHAR, LONGVARCHAR (and vice versa), the apidoc doesn't mention
the fixed and floating point types. Presumably this was added because
you can also call getInt on a double, etc.

> @vlsi, @davecramer, what is your opinion about blindly convert
> incorrect values to false? Should the driver accept this kind of
> behaviour?
>
> For instance something like this is allowed (and there is even a test
> for this):
>
> CREATE TABLE testboolstring (a varchar(30));
> INSERT INTO testboolstring VALUES('this is not true');
>
> when execute rs.getBoolean(1), it gets false, but it should be an
> cannotCastException.

You're right, but the question is: will you break existing code if you
apply this change?

Mark


Re: [JDBC] JDBC String to Bool spec

От
Dave Cramer
Дата:

On 16 January 2017 at 15:09, Mark Rotteveel <mark@lawinegevaar.nl> wrote:
On 2017-01-16 20:16, Jorge Solórzano wrote:
I guess you are right, the driver currently blindly converts incorrect
values to false, IMO it should accept only values allowed in
postgresql server since this is the PgJBDC driver, but is should also
support a cast of float, double and decimal as this is required by the
jdbc spec.

Interestingly, the JDBC 4.2 specification documentation allows more types than the apidoc (see my previous email for a quote of the apidoc). I will see if I can get Lance Andersen to amend the apidoc.

The JDBC specification mentions conversion for: TINYINT, SMALLINT, INTEGER, BIGINT, REAL, FLOAT, DOUBLE, DECIMAL, NUMERIC, BIT, BOOLEAN, CHAR, VARCHAR, LONGVARCHAR (and vice versa), the apidoc doesn't mention the fixed and floating point types. Presumably this was added because you can also call getInt on a double, etc.

@vlsi, @davecramer, what is your opinion about blindly convert
incorrect values to false? Should the driver accept this kind of
behaviour?

For instance something like this is allowed (and there is even a test
for this):

CREATE TABLE testboolstring (a varchar(30));
INSERT INTO testboolstring VALUES('this is not true');

when execute rs.getBoolean(1), it gets false, but it should be an
cannotCastException.

You're right, but the question is: will you break existing code if you apply this change?

what does fixing this give us ? 

I'm also not in favour of fixing it just "cuz"

Re: JDBC String to Bool spec

От
Dave Cramer
Дата:

On 16 January 2017 at 15:09, Mark Rotteveel <mark@lawinegevaar.nl> wrote:
On 2017-01-16 20:16, Jorge Solórzano wrote:
I guess you are right, the driver currently blindly converts incorrect
values to false, IMO it should accept only values allowed in
postgresql server since this is the PgJBDC driver, but is should also
support a cast of float, double and decimal as this is required by the
jdbc spec.

Interestingly, the JDBC 4.2 specification documentation allows more types than the apidoc (see my previous email for a quote of the apidoc). I will see if I can get Lance Andersen to amend the apidoc.

The JDBC specification mentions conversion for: TINYINT, SMALLINT, INTEGER, BIGINT, REAL, FLOAT, DOUBLE, DECIMAL, NUMERIC, BIT, BOOLEAN, CHAR, VARCHAR, LONGVARCHAR (and vice versa), the apidoc doesn't mention the fixed and floating point types. Presumably this was added because you can also call getInt on a double, etc.

@vlsi, @davecramer, what is your opinion about blindly convert
incorrect values to false? Should the driver accept this kind of
behaviour?

For instance something like this is allowed (and there is even a test
for this):

CREATE TABLE testboolstring (a varchar(30));
INSERT INTO testboolstring VALUES('this is not true');

when execute rs.getBoolean(1), it gets false, but it should be an
cannotCastException.

You're right, but the question is: will you break existing code if you apply this change?

what does fixing this give us ? 

I'm also not in favour of fixing it just "cuz"

Re: JDBC String to Bool spec

От
Kevin Wooten
Дата:
I agree it should support all the types the JDBC spec says it should; and it does.  I’m focused on the CHAR/VARCHAR  to Boolean conversion.

To add to your example

CREATE TABLE testboolstring (a varchar(30));

INSERT INTO testboolstring VALUES('this is not true’);
>> ResultSet.getBoolean(1) returns FALSE

INSERT INTO testboolstring VALUES(‘1.0’);
>> ResultSet.getBoolean(1) returns TRUE

INSERT INTO testboolstring VALUES(2.2’);
>> ResultSet.getBoolean(1) returns FALSE


Since we now know the JDBC spec doesn’t support this (thanks to all of Mark Rotteveel’s sleuthing) & we know Postgres doesn’t support this.  It seems the “feature" should be removed or placed behind an option.  Postgres results in an error here and considering this is a driver tied to that database I look to that to clarify ambiguity. These examples should all result in an error.


On Jan 16, 2017, at 12:16 PM, Jorge Solórzano <jorsol@gmail.com> wrote:

I guess you are right, the driver currently blindly converts incorrect values to false, IMO it should accept only values allowed in postgresql server since this is the PgJBDC driver, but is should also support a cast of float, double and decimal as this is required by the jdbc spec.

@vlsi, @davecramer, what is your opinion about blindly convert incorrect values to false? Should the driver accept this kind of behaviour?

For instance something like this is allowed (and there is even a test for this):

CREATE TABLE testboolstring (a varchar(30));
INSERT INTO testboolstring VALUES('this is not true');

when execute rs.getBoolean(1), it gets false, but it should be an cannotCastException.



Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 7:25 PM, Kevin Wooten <kdubb@me.com> wrote:
Good find on this text. That’s what I couldn’t seem to find in the spec. 

Yes these cases are covered… but so are many other cases outside the JDBC spec; some that even Postgres itself doesn’t support.  That’s kind of what I’m getting at.  It seems that currently we’re just attempting to “convert everything” and I’m not sure that’s the appropriate approach when implementing a strict spec like JDBC.

Also, the current conversion set isn’t normalized at all. When all else fails the  “string -> boolean” conversion code then attempts a “string -> double” conversion and if that succeeds it then tests against “1.0” for true and everything else false.  JDBC does seem to give at least some guidance here, suggesting that it should be a strict “1.0 -> true” or “0.0 -> false” mapping as is implemented for “1 -> true” or “0 -> false”.  

I will reiterate that Postgres doesn’t support anything of the sort.  It has a strict set of true and strict set of false values when converting from “string -> bool” anything else results in an error. Although, it does support more values than outlined in the text quoted below.


On Jan 15, 2017, at 6:14 PM, Jorge Solórzano <jorsol@gmail.com> wrote:

BTW, the JDBC specs (or at least the javadocs) reads this:

If the designated column has a datatype of CHAR or VARCHAR and contains a "0" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 0, a value of false is returned. If the designated column has a datatype of CHAR or VARCHAR and contains a "1" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 1, a value of true is returned.

So this use case is already covered, but I think that having full postgres conversion is a better approach.
 

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 6:59 PM, Jorge Solórzano <jorsol@gmail.com> wrote:
Maybe we should support postgres conversion (https://www.postgresql.org/docs/current/static/datatype-boolean.html), similar to what is already on PgPreparedStatement and setObject.

Can you please open an issue on github to keep track of it?

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 5:54 PM, Kevin Wooten <kdubb@me.com> wrote:
It’s not my use case.  It seems to me the driver should either support JDBC/Java conversions (true/yes => true, everything else false) or Postgres conversions (true/on/t/1 => true, false/off/f/0 => false, everything else error).  

Currently it seems theres a hodgepodge of supported conversion not really defined by the spec or server support; unless they are defined somewhere that I’m not aware off.

On Jan 15, 2017, at 4:42 PM, Dave Cramer <pg@fastcrypt.com> wrote:


On 15 January 2017 at 18:33, Kevin Wooten <kdubb@me.com> wrote:
Actually this table isn’t what I’m looking for.  Related to example I provided below, there doesn’t seem to be a list of “acceptable values” when converting a string to a boolean; only that “getBoolean” must support conversion from VARCHAR/CHAR.



Ya I thought you were looking for something else. Not sure how you deal with your exact use case



 
On Jan 15, 2017, at 4:29 PM, Kevin Wooten <kdubb@me.com> wrote:

Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc










Re: [JDBC] JDBC String to Bool spec

От
Kevin Wooten
Дата:
I agree it should support all the types the JDBC spec says it should; and it does.  I’m focused on the CHAR/VARCHAR  to Boolean conversion.

To add to your example

CREATE TABLE testboolstring (a varchar(30));

INSERT INTO testboolstring VALUES('this is not true’);
>> ResultSet.getBoolean(1) returns FALSE

INSERT INTO testboolstring VALUES(‘1.0’);
>> ResultSet.getBoolean(1) returns TRUE

INSERT INTO testboolstring VALUES(2.2’);
>> ResultSet.getBoolean(1) returns FALSE


Since we now know the JDBC spec doesn’t support this (thanks to all of Mark Rotteveel’s sleuthing) & we know Postgres doesn’t support this.  It seems the “feature" should be removed or placed behind an option.  Postgres results in an error here and considering this is a driver tied to that database I look to that to clarify ambiguity. These examples should all result in an error.


On Jan 16, 2017, at 12:16 PM, Jorge Solórzano <jorsol@gmail.com> wrote:

I guess you are right, the driver currently blindly converts incorrect values to false, IMO it should accept only values allowed in postgresql server since this is the PgJBDC driver, but is should also support a cast of float, double and decimal as this is required by the jdbc spec.

@vlsi, @davecramer, what is your opinion about blindly convert incorrect values to false? Should the driver accept this kind of behaviour?

For instance something like this is allowed (and there is even a test for this):

CREATE TABLE testboolstring (a varchar(30));
INSERT INTO testboolstring VALUES('this is not true');

when execute rs.getBoolean(1), it gets false, but it should be an cannotCastException.



Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 7:25 PM, Kevin Wooten <kdubb@me.com> wrote:
Good find on this text. That’s what I couldn’t seem to find in the spec. 

Yes these cases are covered… but so are many other cases outside the JDBC spec; some that even Postgres itself doesn’t support.  That’s kind of what I’m getting at.  It seems that currently we’re just attempting to “convert everything” and I’m not sure that’s the appropriate approach when implementing a strict spec like JDBC.

Also, the current conversion set isn’t normalized at all. When all else fails the  “string -> boolean” conversion code then attempts a “string -> double” conversion and if that succeeds it then tests against “1.0” for true and everything else false.  JDBC does seem to give at least some guidance here, suggesting that it should be a strict “1.0 -> true” or “0.0 -> false” mapping as is implemented for “1 -> true” or “0 -> false”.  

I will reiterate that Postgres doesn’t support anything of the sort.  It has a strict set of true and strict set of false values when converting from “string -> bool” anything else results in an error. Although, it does support more values than outlined in the text quoted below.


On Jan 15, 2017, at 6:14 PM, Jorge Solórzano <jorsol@gmail.com> wrote:

BTW, the JDBC specs (or at least the javadocs) reads this:

If the designated column has a datatype of CHAR or VARCHAR and contains a "0" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 0, a value of false is returned. If the designated column has a datatype of CHAR or VARCHAR and contains a "1" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 1, a value of true is returned.

So this use case is already covered, but I think that having full postgres conversion is a better approach.
 

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 6:59 PM, Jorge Solórzano <jorsol@gmail.com> wrote:
Maybe we should support postgres conversion (https://www.postgresql.org/docs/current/static/datatype-boolean.html), similar to what is already on PgPreparedStatement and setObject.

Can you please open an issue on github to keep track of it?

Jorge Solórzano
me.jorsol.com

On Sun, Jan 15, 2017 at 5:54 PM, Kevin Wooten <kdubb@me.com> wrote:
It’s not my use case.  It seems to me the driver should either support JDBC/Java conversions (true/yes => true, everything else false) or Postgres conversions (true/on/t/1 => true, false/off/f/0 => false, everything else error).  

Currently it seems theres a hodgepodge of supported conversion not really defined by the spec or server support; unless they are defined somewhere that I’m not aware off.

On Jan 15, 2017, at 4:42 PM, Dave Cramer <pg@fastcrypt.com> wrote:


On 15 January 2017 at 18:33, Kevin Wooten <kdubb@me.com> wrote:
Actually this table isn’t what I’m looking for.  Related to example I provided below, there doesn’t seem to be a list of “acceptable values” when converting a string to a boolean; only that “getBoolean” must support conversion from VARCHAR/CHAR.



Ya I thought you were looking for something else. Not sure how you deal with your exact use case



 
On Jan 15, 2017, at 4:29 PM, Kevin Wooten <kdubb@me.com> wrote:

Thanks… is there a reason those tables were dropped from the 4.2 spec PDF?

On Jan 15, 2017, at 4:26 PM, Dave Cramer <pg@fastcrypt.com> wrote:



On 15 January 2017 at 18:20, Kevin Wooten <kdubb@me.com> wrote:
Does anybody know where in the specification it details the required/acceptable conversions from string values to boolean?  I cannot seem to find it in the PDF for 4.2.

I am curious about some of the conversions that are done.  For example, calling “ResultSet.getBoolean” on a text/varchar column with the value “1.0”.  This conversion succeeds because the driver (both pgjdbc & ng) fallback to decoding the column as a double then converting that by testing it “== 1”; which seems valid but questionable since “!= 0” would also be valid, but vastly different.

This is not allowed by Postgres (e.g. “SELECT “1.0”::bool;” results in an error) and I cannot find anything in JDBC as of yet.

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc










Re: [JDBC] JDBC String to Bool spec

От
Jorge Solórzano
Дата:
On Mon, Jan 16, 2017 at 2:09 PM, Mark Rotteveel <mark@lawinegevaar.nl> wrote:

You're right, but the question is: will you break existing code if you apply this change?

Let's assume that someone writes crappy code​, and that in the database there is a column varchar(10) and it allows any value, then the developer wants to get the boolean of that, and in that column there are those values:

t,
TRUE,
FULSE,
yes, ok,
si,
NO, maybe

So, what if someone thinks that "ok" will return TRUE, if the conversion is allowed this will return FALSE, and you will get a wrong behaviour.
If for instance the database have only valid values, YES, NO, TRUE, FALSE, 1, 0 ON, OFF, then this won't break anything. It will break only when someone is doing something bad, so essentially most good code will work without changing a single line of code.

 I think is far more dangerous to blindly accept any value and cast it to false, that to reject it early.




Mark

Re: JDBC String to Bool spec

От
Jorge Solórzano
Дата:
On Mon, Jan 16, 2017 at 2:09 PM, Mark Rotteveel <mark@lawinegevaar.nl> wrote:

You're right, but the question is: will you break existing code if you apply this change?

Let's assume that someone writes crappy code​, and that in the database there is a column varchar(10) and it allows any value, then the developer wants to get the boolean of that, and in that column there are those values:

t,
TRUE,
FULSE,
yes, ok,
si,
NO, maybe

So, what if someone thinks that "ok" will return TRUE, if the conversion is allowed this will return FALSE, and you will get a wrong behaviour.
If for instance the database have only valid values, YES, NO, TRUE, FALSE, 1, 0 ON, OFF, then this won't break anything. It will break only when someone is doing something bad, so essentially most good code will work without changing a single line of code.

 I think is far more dangerous to blindly accept any value and cast it to false, that to reject it early.




Mark

Re: JDBC String to Bool spec

От
Kevin Wooten
Дата:
Well it really isn’t “just “cuz”.  The driver is implementing a specification not making up it’s own on the fly.  It supposed to align as closely as possible.  The ambiguous items make it hard on others (like myself) who work between drivers.

If it was ambiguous from the spec or it was something Postgres supported as an extension I’d say leave it; it doesn’t appear to be either of those.

On Jan 16, 2017, at 1:21 PM, Dave Cramer <pg@fastcrypt.com> wrote:


On 16 January 2017 at 15:09, Mark Rotteveel <mark@lawinegevaar.nl> wrote:
On 2017-01-16 20:16, Jorge Solórzano wrote:
I guess you are right, the driver currently blindly converts incorrect
values to false, IMO it should accept only values allowed in
postgresql server since this is the PgJBDC driver, but is should also
support a cast of float, double and decimal as this is required by the
jdbc spec.

Interestingly, the JDBC 4.2 specification documentation allows more types than the apidoc (see my previous email for a quote of the apidoc). I will see if I can get Lance Andersen to amend the apidoc.

The JDBC specification mentions conversion for: TINYINT, SMALLINT, INTEGER, BIGINT, REAL, FLOAT, DOUBLE, DECIMAL, NUMERIC, BIT, BOOLEAN, CHAR, VARCHAR, LONGVARCHAR (and vice versa), the apidoc doesn't mention the fixed and floating point types. Presumably this was added because you can also call getInt on a double, etc.

@vlsi, @davecramer, what is your opinion about blindly convert
incorrect values to false? Should the driver accept this kind of
behaviour?

For instance something like this is allowed (and there is even a test
for this):

CREATE TABLE testboolstring (a varchar(30));
INSERT INTO testboolstring VALUES('this is not true');

when execute rs.getBoolean(1), it gets false, but it should be an
cannotCastException.

You're right, but the question is: will you break existing code if you apply this change?

what does fixing this give us ? 

I'm also not in favour of fixing it just "cuz"


Re: [JDBC] JDBC String to Bool spec

От
Kevin Wooten
Дата:
Well it really isn’t “just “cuz”.  The driver is implementing a specification not making up it’s own on the fly.  It supposed to align as closely as possible.  The ambiguous items make it hard on others (like myself) who work between drivers.

If it was ambiguous from the spec or it was something Postgres supported as an extension I’d say leave it; it doesn’t appear to be either of those.

On Jan 16, 2017, at 1:21 PM, Dave Cramer <pg@fastcrypt.com> wrote:


On 16 January 2017 at 15:09, Mark Rotteveel <mark@lawinegevaar.nl> wrote:
On 2017-01-16 20:16, Jorge Solórzano wrote:
I guess you are right, the driver currently blindly converts incorrect
values to false, IMO it should accept only values allowed in
postgresql server since this is the PgJBDC driver, but is should also
support a cast of float, double and decimal as this is required by the
jdbc spec.

Interestingly, the JDBC 4.2 specification documentation allows more types than the apidoc (see my previous email for a quote of the apidoc). I will see if I can get Lance Andersen to amend the apidoc.

The JDBC specification mentions conversion for: TINYINT, SMALLINT, INTEGER, BIGINT, REAL, FLOAT, DOUBLE, DECIMAL, NUMERIC, BIT, BOOLEAN, CHAR, VARCHAR, LONGVARCHAR (and vice versa), the apidoc doesn't mention the fixed and floating point types. Presumably this was added because you can also call getInt on a double, etc.

@vlsi, @davecramer, what is your opinion about blindly convert
incorrect values to false? Should the driver accept this kind of
behaviour?

For instance something like this is allowed (and there is even a test
for this):

CREATE TABLE testboolstring (a varchar(30));
INSERT INTO testboolstring VALUES('this is not true');

when execute rs.getBoolean(1), it gets false, but it should be an
cannotCastException.

You're right, but the question is: will you break existing code if you apply this change?

what does fixing this give us ? 

I'm also not in favour of fixing it just "cuz"


Re: [JDBC] JDBC String to Bool spec

От
Jorge Solórzano
Дата:

On Mon, Jan 16, 2017 at 2:22 PM, Kevin Wooten <kdubb@me.com> wrote:
I agree it should support all the types the JDBC spec says it should; and it does.  I’m focused on the CHAR/VARCHAR  to Boolean conversion.

To add to your example

CREATE TABLE testboolstring (a varchar(30));

INSERT INTO testboolstring VALUES('this is not true’);
>> ResultSet.getBoolean(1) returns FALSE

INSERT INTO testboolstring VALUES(‘1.0’);
>> ResultSet.getBoolean(1) returns TRUE

INSERT INTO testboolstring VALUES(2.2’);
>> ResultSet.getBoolean(1) returns FALSE


Since we now know the JDBC spec doesn’t support this (thanks to all of Mark Rotteveel’s sleuthing) & we know Postgres doesn’t support this.  It seems the “feature" should be removed or placed behind an option.  Postgres results in an error here and considering this is a driver tied to that database I look to that to clarify ambiguity. These examples should all result in an error.



​Yes, I agree, a "feature"​ that allows bad code should be considered a "bug".


Re: JDBC String to Bool spec

От
Jorge Solórzano
Дата:

On Mon, Jan 16, 2017 at 2:22 PM, Kevin Wooten <kdubb@me.com> wrote:
I agree it should support all the types the JDBC spec says it should; and it does.  I’m focused on the CHAR/VARCHAR  to Boolean conversion.

To add to your example

CREATE TABLE testboolstring (a varchar(30));

INSERT INTO testboolstring VALUES('this is not true’);
>> ResultSet.getBoolean(1) returns FALSE

INSERT INTO testboolstring VALUES(‘1.0’);
>> ResultSet.getBoolean(1) returns TRUE

INSERT INTO testboolstring VALUES(2.2’);
>> ResultSet.getBoolean(1) returns FALSE


Since we now know the JDBC spec doesn’t support this (thanks to all of Mark Rotteveel’s sleuthing) & we know Postgres doesn’t support this.  It seems the “feature" should be removed or placed behind an option.  Postgres results in an error here and considering this is a driver tied to that database I look to that to clarify ambiguity. These examples should all result in an error.



​Yes, I agree, a "feature"​ that allows bad code should be considered a "bug".


Re: [JDBC] JDBC String to Bool spec

От
rob stone
Дата:
Hello,
> >
> > Since we now know the JDBC spec doesn’t support this (thanks to all
> > of Mark Rotteveel’s sleuthing) & we know Postgres doesn’t support
> > this.  It seems the “feature" should be removed or placed behind an
> > option.  Postgres results in an error here and considering this is
> > a driver tied to that database I look to that to clarify ambiguity.
> > These examples should all result in an error.
> >
> >
> >
>
> Yes, I agree, a "feature" that allows bad code should be considered
> a "bug".
>
>

The OP in the original post used a string of "1.0" and wanted to
convert it into a boolean. If you use setBoolean in a prepared
statement it expects the argument to be a "numeric" type, so it is not
surprising that the string was converted to a double. You'd expect
something along the lines of ps.setBoolean(5,"xyz") to throw an error.

I don't know how many string values are to be considered "true" in the
application. Maybe use some regular expressions to suss out "true"
values?

My two cents.

Rob


Re: JDBC String to Bool spec

От
rob stone
Дата:
Hello,
> >
> > Since we now know the JDBC spec doesn’t support this (thanks to all
> > of Mark Rotteveel’s sleuthing) & we know Postgres doesn’t support
> > this.  It seems the “feature" should be removed or placed behind an
> > option.  Postgres results in an error here and considering this is
> > a driver tied to that database I look to that to clarify ambiguity.
> > These examples should all result in an error.
> >
> >
> >
>
> Yes, I agree, a "feature" that allows bad code should be considered
> a "bug".
>
>

The OP in the original post used a string of "1.0" and wanted to
convert it into a boolean. If you use setBoolean in a prepared
statement it expects the argument to be a "numeric" type, so it is not
surprising that the string was converted to a double. You'd expect
something along the lines of ps.setBoolean(5,"xyz") to throw an error.

I don't know how many string values are to be considered "true" in the
application. Maybe use some regular expressions to suss out "true"
values?

My two cents.

Rob


Re: [JDBC] JDBC String to Bool spec

От
Kevin Wooten
Дата:
As the OP I’d like to make a clarification….

I didn’t want to use a string of “1.0” and convert it to a Boolean.  The driver, in its test suite, tests for this specific case (and a few others). These seemed really out of the norm since the database doesn’t support this.  Thus my investigation began.

On Jan 16, 2017, at 2:16 PM, rob stone <floriparob@gmail.com> wrote:

Hello,

Since we now know the JDBC spec doesn’t support this (thanks to all
of Mark Rotteveel’s sleuthing) & we know Postgres doesn’t support
this.  It seems the “feature" should be removed or placed behind an
option.  Postgres results in an error here and considering this is
a driver tied to that database I look to that to clarify ambiguity.
These examples should all result in an error.




Yes, I agree, a "feature" that allows bad code should be considered
a "bug".



The OP in the original post used a string of "1.0" and wanted to
convert it into a boolean. If you use setBoolean in a prepared
statement it expects the argument to be a "numeric" type, so it is not
surprising that the string was converted to a double. You'd expect
something along the lines of ps.setBoolean(5,"xyz") to throw an error.

I don't know how many string values are to be considered "true" in the
application. Maybe use some regular expressions to suss out "true"
values?

My two cents.

Rob


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc

Re: JDBC String to Bool spec

От
Kevin Wooten
Дата:
As the OP I’d like to make a clarification….

I didn’t want to use a string of “1.0” and convert it to a Boolean.  The driver, in its test suite, tests for this specific case (and a few others). These seemed really out of the norm since the database doesn’t support this.  Thus my investigation began.

On Jan 16, 2017, at 2:16 PM, rob stone <floriparob@gmail.com> wrote:

Hello,

Since we now know the JDBC spec doesn’t support this (thanks to all
of Mark Rotteveel’s sleuthing) & we know Postgres doesn’t support
this.  It seems the “feature" should be removed or placed behind an
option.  Postgres results in an error here and considering this is
a driver tied to that database I look to that to clarify ambiguity.
These examples should all result in an error.




Yes, I agree, a "feature" that allows bad code should be considered
a "bug".



The OP in the original post used a string of "1.0" and wanted to
convert it into a boolean. If you use setBoolean in a prepared
statement it expects the argument to be a "numeric" type, so it is not
surprising that the string was converted to a double. You'd expect
something along the lines of ps.setBoolean(5,"xyz") to throw an error.

I don't know how many string values are to be considered "true" in the
application. Maybe use some regular expressions to suss out "true"
values?

My two cents.

Rob


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc

Re: [JDBC] JDBC String to Bool spec

От
Dave Cramer
Дата:
Seems to me we can introduce a breaking change in version 42. If this becomes an issue then we can put it back behind an option as Kevin suggested.


On 16 January 2017 at 16:20, Kevin Wooten <kdubb@me.com> wrote:
As the OP I’d like to make a clarification….

I didn’t want to use a string of “1.0” and convert it to a Boolean.  The driver, in its test suite, tests for this specific case (and a few others). These seemed really out of the norm since the database doesn’t support this.  Thus my investigation began.

On Jan 16, 2017, at 2:16 PM, rob stone <floriparob@gmail.com> wrote:

Hello,

Since we now know the JDBC spec doesn’t support this (thanks to all
of Mark Rotteveel’s sleuthing) & we know Postgres doesn’t support
this.  It seems the “feature" should be removed or placed behind an
option.  Postgres results in an error here and considering this is
a driver tied to that database I look to that to clarify ambiguity.
These examples should all result in an error.




Yes, I agree, a "feature" that allows bad code should be considered
a "bug".



The OP in the original post used a string of "1.0" and wanted to
convert it into a boolean. If you use setBoolean in a prepared
statement it expects the argument to be a "numeric" type, so it is not
surprising that the string was converted to a double. You'd expect
something along the lines of ps.setBoolean(5,"xyz") to throw an error.

I don't know how many string values are to be considered "true" in the
application. Maybe use some regular expressions to suss out "true"
values?

My two cents.

Rob


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc


Re: JDBC String to Bool spec

От
Dave Cramer
Дата:
Seems to me we can introduce a breaking change in version 42. If this becomes an issue then we can put it back behind an option as Kevin suggested.


On 16 January 2017 at 16:20, Kevin Wooten <kdubb@me.com> wrote:
As the OP I’d like to make a clarification….

I didn’t want to use a string of “1.0” and convert it to a Boolean.  The driver, in its test suite, tests for this specific case (and a few others). These seemed really out of the norm since the database doesn’t support this.  Thus my investigation began.

On Jan 16, 2017, at 2:16 PM, rob stone <floriparob@gmail.com> wrote:

Hello,

Since we now know the JDBC spec doesn’t support this (thanks to all
of Mark Rotteveel’s sleuthing) & we know Postgres doesn’t support
this.  It seems the “feature" should be removed or placed behind an
option.  Postgres results in an error here and considering this is
a driver tied to that database I look to that to clarify ambiguity.
These examples should all result in an error.




Yes, I agree, a "feature" that allows bad code should be considered
a "bug".



The OP in the original post used a string of "1.0" and wanted to
convert it into a boolean. If you use setBoolean in a prepared
statement it expects the argument to be a "numeric" type, so it is not
surprising that the string was converted to a double. You'd expect
something along the lines of ps.setBoolean(5,"xyz") to throw an error.

I don't know how many string values are to be considered "true" in the
application. Maybe use some regular expressions to suss out "true"
values?

My two cents.

Rob


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc


Re: JDBC String to Bool spec

От
"David G. Johnston"
Дата:
+1

On Mon, Jan 16, 2017 at 2:39 PM, Dave Cramer <pg@fastcrypt.com> wrote:
Seems to me we can introduce a breaking change in version 42. If this becomes an issue then we can put it back behind an option as Kevin suggested.


On 16 January 2017 at 16:20, Kevin Wooten <kdubb@me.com> wrote:
As the OP I’d like to make a clarification….

I didn’t want to use a string of “1.0” and convert it to a Boolean.  The driver, in its test suite, tests for this specific case (and a few others). These seemed really out of the norm since the database doesn’t support this.  Thus my investigation began.

On Jan 16, 2017, at 2:16 PM, rob stone <floriparob@gmail.com> wrote:

Hello,

Since we now know the JDBC spec doesn’t support this (thanks to all
of Mark Rotteveel’s sleuthing) & we know Postgres doesn’t support
this.  It seems the “feature" should be removed or placed behind an
option.  Postgres results in an error here and considering this is
a driver tied to that database I look to that to clarify ambiguity.
These examples should all result in an error.




Yes, I agree, a "feature" that allows bad code should be considered
a "bug".



The OP in the original post used a string of "1.0" and wanted to
convert it into a boolean. If you use setBoolean in a prepared
statement it expects the argument to be a "numeric" type, so it is not
surprising that the string was converted to a double. You'd expect
something along the lines of ps.setBoolean(5,"xyz") to throw an error.

I don't know how many string values are to be considered "true" in the
application. Maybe use some regular expressions to suss out "true"
values?

My two cents.

Rob


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



Re: [JDBC] JDBC String to Bool spec

От
"David G. Johnston"
Дата:
+1

On Mon, Jan 16, 2017 at 2:39 PM, Dave Cramer <pg@fastcrypt.com> wrote:
Seems to me we can introduce a breaking change in version 42. If this becomes an issue then we can put it back behind an option as Kevin suggested.


On 16 January 2017 at 16:20, Kevin Wooten <kdubb@me.com> wrote:
As the OP I’d like to make a clarification….

I didn’t want to use a string of “1.0” and convert it to a Boolean.  The driver, in its test suite, tests for this specific case (and a few others). These seemed really out of the norm since the database doesn’t support this.  Thus my investigation began.

On Jan 16, 2017, at 2:16 PM, rob stone <floriparob@gmail.com> wrote:

Hello,

Since we now know the JDBC spec doesn’t support this (thanks to all
of Mark Rotteveel’s sleuthing) & we know Postgres doesn’t support
this.  It seems the “feature" should be removed or placed behind an
option.  Postgres results in an error here and considering this is
a driver tied to that database I look to that to clarify ambiguity.
These examples should all result in an error.




Yes, I agree, a "feature" that allows bad code should be considered
a "bug".



The OP in the original post used a string of "1.0" and wanted to
convert it into a boolean. If you use setBoolean in a prepared
statement it expects the argument to be a "numeric" type, so it is not
surprising that the string was converted to a double. You'd expect
something along the lines of ps.setBoolean(5,"xyz") to throw an error.

I don't know how many string values are to be considered "true" in the
application. Maybe use some regular expressions to suss out "true"
values?

My two cents.

Rob


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



Re: JDBC String to Bool spec

От
Jorge Solórzano
Дата:
Just FYI this is the PR related: https://github.com/pgjdbc/pgjdbc/pull/732

Re: [JDBC] JDBC String to Bool spec

От
Jorge Solórzano
Дата:
Just FYI this is the PR related: https://github.com/pgjdbc/pgjdbc/pull/732