All we need is an easy explanation of the problem, so here it is.
PostgreSQL has a type called char
that’s stored as an signed 1 byte int
The type
"char"
(note the quotes) is different fromchar(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" );
How to solve :
I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.
Method 1
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:
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0