Re: [pgsql-sql] Daily digest v1.3328 (5 messages)

Started by TJ O'Donnellover 15 years ago6 messagesgeneral
Jump to latest
#1TJ O'Donnell
tjo@acm.org

Many frameworks do not natively recognize "t" as true and "f" as false.
I'm using php, json_encode and extjs.
Is it possible to cause the default output of boolean values to be something
other than "t" and "f", say "true" and "false" or even 1 and 0?
Of course I can do this for an individual query using appropriate functions, but
it would help me to be able to modify the default behavior.

TJ

#2Adrian Klaver
adrian.klaver@aklaver.com
In reply to: TJ O'Donnell (#1)

On Wednesday 22 September 2010 5:12:45 pm TJ O'Donnell wrote:

Many frameworks do not natively recognize "t" as true and "f" as false.
I'm using php, json_encode and extjs.
Is it possible to cause the default output of boolean values to be
something other than "t" and "f", say "true" and "false" or even 1 and 0?
Of course I can do this for an individual query using appropriate
functions, but it would help me to be able to modify the default behavior.

TJ

From here;

http://www.postgresql.org/docs/8.4/interactive/datatype-boolean.html

Valid literal values for the "true" state are:

TRUE
't'
'true'
'y'
'yes'
'on'
'1'

For the "false" state, the following values can be used:

FALSE
'f'
'false'
'n'
'no'
'off'
'0'

--
Adrian Klaver
adrian.klaver@gmail.com

#3David Wilson
david.t.wilson@gmail.com
In reply to: Adrian Klaver (#2)

On Wed, Sep 22, 2010 at 8:30 PM, Adrian Klaver <adrian.klaver@gmail.com>wrote:

From here;

http://www.postgresql.org/docs/8.4/interactive/datatype-boolean.html

I believe the question relates to changing the string *output* of the
database to something other than 't' and 'f', not an issue with input
formats.

--
- David T. Wilson
david.t.wilson@gmail.com

#4Adrian Klaver
adrian.klaver@aklaver.com
In reply to: David Wilson (#3)

On Wednesday 22 September 2010 5:40:55 pm David Wilson wrote:

On Wed, Sep 22, 2010 at 8:30 PM, Adrian Klaver <adrian.klaver@gmail.com>wrote:

From here;

http://www.postgresql.org/docs/8.4/interactive/datatype-boolean.html

I believe the question relates to changing the string *output* of the
database to something other than 't' and 'f', not an issue with input
formats.

Oops missed that. This would seem to an adapter problem. I work with Python and
psycopg2 adapts the boolean values to True and False. Not sure about the PHP
solution.

--
Adrian Klaver
adrian.klaver@gmail.com

In reply to: Adrian Klaver (#4)

On 23/09/2010 02:00, Adrian Klaver wrote:

On Wednesday 22 September 2010 5:40:55 pm David Wilson wrote:

On Wed, Sep 22, 2010 at 8:30 PM, Adrian Klaver<adrian.klaver@gmail.com>wrote:

From here;

http://www.postgresql.org/docs/8.4/interactive/datatype-boolean.html

I believe the question relates to changing the string *output* of the
database to something other than 't' and 'f', not an issue with input
formats.

Oops missed that. This would seem to an adapter problem. I work with Python and
psycopg2 adapts the boolean values to True and False. Not sure about the PHP
solution.

AFAIK the native functions (pg_query() etc) output 't' and 'f', but PDO
(which I've been using in the context of Zend Framework) output "real"
true and false values.

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

#6TJ O'Donnell
tjo@acm.org
In reply to: Raymond O'Donnell (#5)

Yes indeed, pg_query returns "t" or "f" as strings when selecting
boolean columns.
I was able to switch over to PDO with only an afternoon's work and it works
perfectly for boolean columns, returning values that are properly interpreted
as true and false by php, and by json_encode. I'm all set now.
Thanks for the help!

TJ O'Donnell

Show quoted text

On Thu, Sep 23, 2010 at 1:18 AM, Raymond O'Donnell <rod@iol.ie> wrote:

On 23/09/2010 02:00, Adrian Klaver wrote:

On Wednesday 22 September 2010 5:40:55 pm David Wilson wrote:

On Wed, Sep 22, 2010 at 8:30 PM, Adrian
Klaver<adrian.klaver@gmail.com>wrote:

 From here;

http://www.postgresql.org/docs/8.4/interactive/datatype-boolean.html

I believe the question relates to changing the string *output* of the
database to something other than 't' and 'f', not an issue with input
formats.

Oops missed that. This would seem to an adapter problem. I work with
Python and
psycopg2 adapts the boolean values to True and False. Not sure about the
PHP
solution.

AFAIK the native functions (pg_query() etc) output 't' and 'f', but PDO
(which I've been using in the context of Zend Framework) output "real" true
and false values.

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie