Home > Software engineering >  code convert unique chars to '?' in postgreSQL queries
code convert unique chars to '?' in postgreSQL queries

Time:04-18

I have an automation code that runs a bunch of queries into Postgresql DB.

one of my queries is :

CREATE TABLE 行 (CustomerName int, City varchar(255),Country varchar(255))

when running it into the DB, I got this response:

Query response from db: 
CREATE TABLE ? (CustomerName int, City varchar(255),Country varchar(255));
ERROR:  syntax error at or near "?"
LINE 1: CREATE TABLE ? (CustomerName int, City varchar(255),Country ...
                     ^
postgres=# 

it seems that it converts the unique char to '?'.

any suggestion why this could happen?

I'm sure that before the query is executed the letters are encoded correctly.

(when running this query manually everything goes well)

CodePudding user response:

I would avoid using keyword characters, or international characters.

If you really need to do that you can try to use " double quote

Quoted identifiers can contain any character, except the character with code zero. (To include a double quote, write two double-quotes.) This allows constructing table or column names that would otherwise not be possible, such as ones containing spaces or ampersands. The length limitation still applies.

SQL-SYNTAX-IDENTIFIERS

CREATE TABLE "行" (CustomerName int, City varchar(255),Country varchar(255))
  • Related