Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

char data type #101

Open
hcheng2002cn opened this issue Apr 12, 2021 · 1 comment
Open

char data type #101

hcheng2002cn opened this issue Apr 12, 2021 · 1 comment
Labels

Comments

@hcheng2002cn
Copy link

  • "CREATE TABLE brintest (charcol char)" parse char data type as bpchar:
{"ColumnDef":{"colname":"charcol","typeName":{"names":[{"String":{"str":"pg_catalog"}},{"String":{"str":"bpchar"}}],"typmods":[{"A_Const":{"val":{"Integer":{"ival":1}},"location":-1}}],"typemod":-1,"location":48},"is_local":true,"location":40}}
  • "CREATE TABLE brintest (charcol "char")" parse "char" data type as char:
{"ColumnDef":{"colname":"charcol","typeName":{"names":[{"String":{"str":"char"}}],"typemod":-1,"location":48},"is_local":true,"location":40}}
  • "CREATE TABLE brintest (charcol char(1))" parse char data type as bpchar:
{"ColumnDef":{"colname":"charcol","typeName":{"names":[{"String":{"str":"pg_catalog"}},{"String":{"str":"bpchar"}}],"typmods":[{"A_Const":{"val":{"Integer":{"ival":1}},"location":-1}}],"typemod":-1,"location":48},"is_local":true,"location":40}}

Is it correct ?

Thanks
hong

@lfittl
Copy link
Member

lfittl commented May 7, 2021

Hi @hcheng2002cn,

Yes, this is since the Postgres parser special cases the character data types (see here: https://github.com/postgres/postgres/blob/master/src/backend/parser/gram.y#L13095)

When you specify the type as "char" on the other hand you avoid all that logic, since you are telling Postgres the exact type name you want to reference.

@lfittl lfittl added the question label May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants