Database 如何用Perl显示Postgres表
我已经尝试在perl中使用\d命令,这就是我得到的结果 DBD::Pg::st执行失败:错误:在“d”处或附近出现语法错误 这是我的密码Database 如何用Perl显示Postgres表,database,postgresql,perl,Database,Postgresql,Perl,我已经尝试在perl中使用\d命令,这就是我得到的结果 DBD::Pg::st执行失败:错误:在“d”处或附近出现语法错误 这是我的密码 #!/usr/bin/perl use DBI; $myConnection = DBI->connect("DBI:Pg:dbname=test;host=localhost","postgres", "pass123"); $query = $myConnection->prepare("\d"); $result = $query-&g
#!/usr/bin/perl
use DBI;
$myConnection = DBI->connect("DBI:Pg:dbname=test;host=localhost","postgres", "pass123");
$query = $myConnection->prepare("\d");
$result = $query->execute();
while(my @row = $sth->fetchrow_array()) {
print "ID = ". $row[0] . "\n";
}
$myConnection->disconnect();
最简单、最可移植的方法是使用该函数。最简单、最可移植的方法是使用该函数。如果您只需要表或视图列表,可以使用
my @tables = $dbh->tables();
您还可以将列表限制为特定的架构。例如,要仅获取public
模式中的表,而不获取pg_目录
和information_模式
表,请执行以下操作:
my @tables = $dbh->tables(undef, 'public');
有关详细信息,请参阅
有关表格的详细信息,请按照中的建议使用
table\u info
如果您只需要表格或视图列表,可以使用
my @tables = $dbh->tables();
您还可以将列表限制为特定的架构。例如,要仅获取public
模式中的表,而不获取pg_目录
和information_模式
表,请执行以下操作:
my @tables = $dbh->tables(undef, 'public');
有关详细信息,请参阅
有关表的更多信息,请使用
table\u info
,如中所述,反斜杠在双引号Perl字符串中具有特殊含义。要么转义反斜杠(“\\d”
)要么使用单引号字符串(“\d”
)。我假设\d
是psql
实用程序的命令,不能通过DBI作为SQL查询使用。我尝试了\\d而“\d”什么都不起作用什么是“Postgres故事”?反斜杠在双引号Perl字符串中有特殊含义。要么转义反斜杠(“\\d”
),要么使用单引号字符串(“\d”
)。我假设\d
是psql
实用程序的命令,不能通过DBI作为SQL查询使用。我尝试了\\d而“\d”什么都不起作用什么是“Postgres故事”?