0

I have tried using the \d command inside perl and this is what i get

DBD::Pg::st execute failed: ERROR: syntax error at or near "d"

This is My Code

#!/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();
4
  • A backslash has a special meaning in a double-quoted Perl string. Either escape the backslash ("\\d") or use a single-quoted string ('\d'). Commented Jul 21, 2017 at 11:27
  • 4
    I would assume that \d is a command of the psql utility and not available as a SQL query via DBI. Commented Jul 21, 2017 at 11:31
  • i tried \\d and '\d' nothing works Commented Jul 21, 2017 at 14:12
  • What is a "Postgres Tale"? Commented Jul 21, 2017 at 15:06

2 Answers 2

2

The simplest and most portable way is to use the table_info function.

Sign up to request clarification or add additional context in comments.

Comments

1

If you only want the list of tables or views, you can use

my @tables = $dbh->tables();

You can also restrict the list to a specific schema. For example, to get only the tables in the public schema, without the pg_catalog and information_schema tables:

my @tables = $dbh->tables(undef, 'public');

See https://metacpan.org/pod/DBD::Pg#tables for details.

For more information about the tables, use table_info as suggested in Laurenz' answer

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.