In Django, I'm trying to use \dt
in cursor.execute()
to get the tables in PostgreSQL as shown below:
# "views.py"
from django.http import HttpResponse
from django.db import connection
def test(request):
cursor = connection.cursor()
cursor.execute('''\dt''') # Here
row = cursor.fetchone()
print(row)
return HttpResponse("Test")
But, I got the error below:
django.db.utils.ProgrammingError: syntax error at or near "\"
LINE 1: \dt
So, I replaced cursor.execute('''\dt''')
with cursor.execute('''\\dt''')
as shown below:
# "views.py"
from django.http import HttpResponse
from django.db import connection
def test(request):
# ...
cursor.execute('''\\dt''') # Here
# ...
return HttpResponse("Test")
But, I still got the error below:
django.db.utils.ProgrammingError: syntax error at or near "\"
LINE 1: \dt
So, how do I use \dt
in cursor.execute()
to get the tables in PostgreSQL?