Re: Converting yes or no to one letter strings.

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Lou <lou(at)dayspringpublisher(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Converting yes or no to one letter strings.
Date: 2019-06-04 23:23:32
Message-ID: CAKFQuwapnGz0fQP-ZE-coP190vv_NfFWJK+f6NyneFOqH-YP2g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jun 4, 2019 at 3:30 PM Lou <lou(at)dayspringpublisher(dot)com> wrote:

> Is it possible to convert a boolean yes or no field to hold a one letter
> string? For example, the strings: 's' 'f' 'p' 'e'
>
Something like the following should work:

ALTER TABLE ... ALTER COLUMN ... TYPE text USING (CASE WHEN ... THEN 's'
ELSE 'f' END);

https://www.postgresql.org/docs/11/sql-altertable.html

Though at this point you are probably better off creating a category table
with a primary key and converting this column to be a foreign key.

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2019-06-04 23:29:27 Re: Converting yes or no to one letter strings.
Previous Message Ray O'Donnell 2019-06-04 23:03:06 Re: Converting yes or no to one letter strings.