SAS调用PostgreSQL的information_schema遇库名长度超限问题求助
解决SAS调用PostgreSQL information_schema库名过长的问题
方法1:为information_schema创建短别名库
SAS要求库名不超过8字符,你可以通过LIBNAME语句给PostgreSQL的information_schema指定一个短别名(比如INFOSCH),之后通过这个别名访问COLUMNS表:
/* 创建短别名库,关联到PostgreSQL的information_schema */ libname infosch postgres server='你的服务器地址' port='端口' db='你的数据库' schema='information_schema' user='用户名' password='密码'; proc sql; CREATE TABLE table_2 AS SELECT * FROM infosch.columns WHERE TABLE_NAME='table_1'; run; /* 可选:用完后断开库连接 */ libname infosch clear;
方法2:使用SAS直通SQL(Pass-Through)
直接通过直通SQL将查询语句发送给PostgreSQL执行,绕开SAS的库名长度限制——此时SAS仅负责传递语句和接收结果,不需要解析information_schema作为本地库名:
proc sql; connect to postgres (server='你的服务器地址' port='端口' db='你的数据库' user='用户名' password='密码'); CREATE TABLE table_2 AS SELECT * FROM connection to postgres ( SELECT * FROM information_schema.columns WHERE table_name='table_1' ); disconnect from postgres; run;
两种方法都能解决问题:方法1适合需要多次访问information_schema的场景;方法2更适合临时查询,无需额外创建库别名。
内容的提问来源于stack exchange,提问作者Eliana Wassermann
相关产品推荐
相关产品推荐

