Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 500035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:02:46+00:00 2026-05-13T06:02:46+00:00

How can I determine if a table exists using the Psycopg2 Python library? I

  • 0

How can I determine if a table exists using the Psycopg2 Python library? I want a true or false boolean.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:02:46+00:00Added an answer on May 13, 2026 at 6:02 am

    How about:

    >>> import psycopg2
    >>> conn = psycopg2.connect("dbname='mydb' user='username' host='localhost' password='foobar'")
    >>> cur = conn.cursor()
    >>> cur.execute("select * from information_schema.tables where table_name=%s", ('mytable',))
    >>> bool(cur.rowcount)
    True
    

    An alternative using EXISTS is better in that it doesn’t require that all rows be retrieved, but merely that at least one such row exists:

    >>> cur.execute("select exists(select * from information_schema.tables where table_name=%s)", ('mytable',))
    >>> cur.fetchone()[0]
    True
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 498k
  • Answers 498k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Dim StronglyTypedList = OriginalArrayList.Cast(Of MyType)().ToList() ' requires `Imports System.Linq` May 16, 2026 at 12:23 pm
  • Editorial Team
    Editorial Team added an answer you can add the line import pdb; pdb.set_trace() anywhere in… May 16, 2026 at 12:23 pm
  • Editorial Team
    Editorial Team added an answer +1 Good question. You may want to have a look… May 16, 2026 at 12:23 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a hierarchical set-up going on a table using the whole START WITH
I am using LINQ and am having a hard time understanding how I can
Is there a way you can determine the date when a trigger was updated?
I know this is similar to this question , but I'm using SQL Server
Id columns can specify a generator. Perfect. However, I have a situation in which
I need write an update statement that used multiple tables to determine which rows
I am using NHibernate for a project, and I am absolutely beginner. I am
I am looking for a fast sql sentence for determine when a field exist
I have been able to create php function to determine a list of zip
Hey guys, I'm using GWT for a data-driven web application, and I'm having issues

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.