0

PostgreSQL has a type called char that's stored as an signed 1 byte int

The type "char" (note the quotes) is different from char(1) in that it only uses one byte of storage. It is internally used in the system catalogs as a simplistic enumeration type.

Can we create composite types with "char"? I can create a table with it...

CREATE TABLE pixel ( r "char", g "char", b "char" );

Internally that creates a type which I can use elsewhere,

CREATE TABLE f ( mypixel pixel );

But, can I create a simple TYPE (no table) from it?

CREATE TYPE pixel ( r "char", g "char", b "char" );
ERROR:  syntax error at or near ""char""
LINE 1: CREATE TYPE pixel ( r "char", g "char", b "char" );

1 Answer 1

5

It's just the missing keyword AS:

CREATE TYPE pixel AS (r "char", g "char", b "char");

The data type "char" is a non-standard type, primarily meant for internal purposes. But it's just another type - except for the peculiar spelling of the name including the double-quotes to disambiguate against char. See:

2
  • Jesus Christ. they need to decide if AS and TO is optional or not and be consistent. Thanks =) Commented Feb 23, 2018 at 17:58
  • lack of AS changes the meaning here, and it's not really optional other places either, SELECT asnumber AS as, source AS from FROM systems;
    – Jasen
    Commented Apr 14, 2022 at 1:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.