Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi BDE PostgreSQL查询执行(语法错误)_Delphi_Postgresql_Syntax Error_Bde - Fatal编程技术网

Delphi BDE PostgreSQL查询执行(语法错误)

Delphi BDE PostgreSQL查询执行(语法错误),delphi,postgresql,syntax-error,bde,Delphi,Postgresql,Syntax Error,Bde,我正在将BDS 2006与PostgreSQL一起用于我的应用程序。 我有以下代码,其中包含用于在表中查找主键值的查询 Query.SQL.Clear; Query.SQL.Add('SELECT pg_attribute.attname,format_type(pg_attribute.atttypid, pg_attribute.atttypmod)FROM pg_index, pg_class, pg_attribute WHERE pg_class.oid = '+#39+'tabl

我正在将BDS 2006与PostgreSQL一起用于我的应用程序。
我有以下代码,其中包含用于在表中查找主键值的查询

 Query.SQL.Clear;
 Query.SQL.Add('SELECT pg_attribute.attname,format_type(pg_attribute.atttypid, pg_attribute.atttypmod)FROM pg_index, pg_class, pg_attribute WHERE pg_class.oid = '+#39+'tablename'+#39+' ::regclass AND indrelid = pg_class.oid AND pg_attribute.attrelid = pg_class.oid AND pg_attribute.attnum = any(pg_index.indkey)AND indisprimary');
 Query.Open;
我收到一条语法错误消息

 General SQL error.  
 ERROR: syntax error at or near ":";  
我试着用
#58
代替
,但结果相同。
以下查询在我的PostgreSQL中运行良好


关于如何使其工作的任何意见

您可以尝试切换到而不是特定于PostgreSQL的

Query.SQL.Add('SELECT pg_attribute.attname,format_type(pg_attribute.atttypid, pg_attribute.atttypmod)FROM pg_index, pg_class, pg_attribute WHERE pg_class.oid = CAST('+#39+'tablename'+#39+' AS regclass) AND indrelid = pg_class.oid AND pg_attribute.attrelid = pg_class.oid AND pg_attribute.attnum = any(pg_index.indkey) AND indisprimary');

也许Delphi中的某些东西想要使用冒号作为命名占位符。

如果表名包含大写字符,请尝试将其置于双引号之间,例如“MySuperDupleTable”,如果表名不在双引号之间,则postgres会将其名称更改为小写

如果这不能解决您的问题,您可能还想尝试
::regclass
我记得几年前,我们使用了一些需要加倍的Delphi组件:“:”

希望这对您有所帮助。

1)如果您放置了BDE标记,那么我希望您使用的是BDE+BDE ODBC SQLLink+PgSQL ODBC驱动程序。BDE组件期望
:'
作为参数标记,而
:'
作为转义序列,转换为
:'
。您有两个基本选项:

  • TQuery
    ParamCheck
    设置为False,手工填写
    Params
    集合
  • 每一个都加倍
    :'
    ,这不是参数标记。因此,它将是
    ::'

2) 您可以使用3d party库,例如,它们理解PgSQL的含义。因此,他们不会将“
”::”
识别为参数标记。

您正在将sql设置为查询,但您正在对QUERY\u DMP\RES调用OPEN,如果我没有遗漏什么,您会感到疲倦(:我对PostgreSQL一无所知。但是,当您使用“:”时,可能QUERY正在解析sql)(用于指示参数)。请尝试设置
Query.ParamCheck:=False
@DorinDuminica,抱歉,大副已更正it@Shirish11没问题,你解决问题了吗?