{"id":2642,"date":"2026-04-11T09:02:26","date_gmt":"2026-04-11T02:02:26","guid":{"rendered":"https:\/\/www.pgtutorial.com\/?page_id=2642"},"modified":"2026-04-11T10:07:05","modified_gmt":"2026-04-11T03:07:05","slug":"create-table","status":"publish","type":"page","link":"https:\/\/www.pgtutorial.com\/postgresql-python\/create-table\/","title":{"rendered":"PostgreSQL Python: Create Table"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: In this tutorial, you&#8217;ll learn how to create a table in PostgreSQL from Python using Psycopg 3.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites\" id='prerequisites'>Prerequisites <a href=\"#prerequisites\" class=\"anchor\" id=\"prerequisites\" title=\"Anchor for Prerequisites\">#<\/a><\/h2>\n\n\n\n<p>Before you start, make sure you have:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Python installed<\/li>\n\n\n\n<li>PostgreSQL running<\/li>\n\n\n\n<li>A database to connect to, for example: <code>pyinventory<\/code>.<\/li>\n\n\n\n<li>A PostgreSQL user such as <code>postgres<\/code><\/li>\n\n\n\n<li>A virtual environment for your project<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-the-products-table-stores\" id='what-the-products-table-stores'>What the products table stores <a href=\"#what-the-products-table-stores\" class=\"anchor\" id=\"what-the-products-table-stores\" title=\"Anchor for What the products table stores\">#<\/a><\/h2>\n\n\n\n<p>The <code>products<\/code> table stores basic information:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>product_id<\/code> \u2014 the primary key<\/li>\n\n\n\n<li><code>name<\/code> \u2014 the product name<\/li>\n\n\n\n<li><code>price<\/code> \u2014 the product price<\/li>\n\n\n\n<li><code>safety_stock<\/code> \u2014 the minimum stock level to maintain<\/li>\n\n\n\n<li><code>gross_weight<\/code> \u2014 the product&#8217;s gross weight<\/li>\n<\/ul>\n\n\n\n<p>Here&#8217;s the statement for creating the <code>products<\/code> table in PostgreSQL:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> <span class=\"hljs-keyword\">IF<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">EXISTS<\/span> products (\n    product_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">GENERATED<\/span> <span class=\"hljs-keyword\">ALWAYS<\/span> <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n    <span class=\"hljs-keyword\">name<\/span> <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">255<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    price <span class=\"hljs-built_in\">NUMERIC<\/span>(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    safety_stock <span class=\"hljs-built_in\">INTEGER<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    gross_weight <span class=\"hljs-built_in\">NUMERIC<\/span>(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">2<\/span>)\n)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"python-script-for-creating-tables\" id='python-script-for-creating-tables'>Python script for creating tables <a href=\"#python-script-for-creating-tables\" class=\"anchor\" id=\"python-script-for-creating-tables\" title=\"Anchor for Python script for creating tables\">#<\/a><\/h2>\n\n\n\n<p>First, create the <code>create_table.py<\/code> file and use the following code to create the <code>products<\/code> table in the PostgreSQL database:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> psycopg\n<span class=\"hljs-keyword\">from<\/span> config <span class=\"hljs-keyword\">import<\/span> config\n\ncreate_table_sql = <span class=\"hljs-string\">\"\"\"\n    CREATE TABLE IF NOT EXISTS products (\n        product_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,\n        name VARCHAR(255) NOT NULL,\n        price NUMERIC(10, 2) NOT NULL,\n        safety_stock INTEGER NOT NULL,\n        gross_weight NUMERIC(10, 2)\n    )\n    \"\"\"<\/span>\n\n<span class=\"hljs-keyword\">try<\/span>:\n    <span class=\"hljs-keyword\">with<\/span> psycopg.connect(**config) <span class=\"hljs-keyword\">as<\/span> conn:\n        <span class=\"hljs-keyword\">with<\/span> conn.cursor() <span class=\"hljs-keyword\">as<\/span> cur:\n            cur.execute(create_table_sql)\n            print(<span class=\"hljs-string\">\"The products table has been created successfully.\"<\/span>)\n<span class=\"hljs-keyword\">except<\/span> Exception <span class=\"hljs-keyword\">as<\/span> e:\n    print(<span class=\"hljs-string\">f\"Error: <span class=\"hljs-subst\">{e}<\/span>\"<\/span>)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>How it works:<\/p>\n\n\n\n<p>Step 1. Import <code>psycopg<\/code> and <code>config<\/code> module:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> psycopg\n<span class=\"hljs-keyword\">from<\/span> config <span class=\"hljs-keyword\">import<\/span> config\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Step 2. Define a variable to store the <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-create-table\/\" type=\"page\" id=\"81\"><code>CREATE TABLE <\/code>statement<\/a>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">create_table_sql = <span class=\"hljs-string\">\"\"\"\n    CREATE TABLE IF NOT EXISTS products (\n        product_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,\n        name VARCHAR(255) NOT NULL,\n        price NUMERIC(10, 2) NOT NULL,\n        safety_stock INTEGER NOT NULL,\n        gross_weight NUMERIC(10, 2)\n    )\n    \"\"\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Step 3. Execute the <code>CREATE TABLE<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">with<\/span> psycopg.connect(**config) <span class=\"hljs-keyword\">as<\/span> conn:\n    <span class=\"hljs-keyword\">with<\/span> conn.cursor() <span class=\"hljs-keyword\">as<\/span> cur:\n        cur.execute(create_table_sql)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Second, run the script by executing the <code>create_table.py<\/code> file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">python create_table.py<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>If the script succeeds, you should see:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">The products table has been created successfully.\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"verify-the-table\" id='verify-the-table'>Verify the table <a href=\"#verify-the-table\" class=\"anchor\" id=\"verify-the-table\" title=\"Anchor for Verify the table\">#<\/a><\/h2>\n\n\n\n<p>Step 1. Open the Command Prompt on Windows or Terminal on macOS:<\/p>\n\n\n\n<p>Step 2. Connect to the <code>pyinventory<\/code> database on the local PostgreSQL server using psql:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">psql -U postgres -d pyinventory<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Step 3.  Use the <code>\\dt<\/code> command to show tables in the <code>pyinventory<\/code> database:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">\\dt<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>If everything is fine, you should see the following output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">        List of relations\nSchema |   Name   | Type  |  Owner\n--------+----------+-------+----------\npublic | products | table | postgres\n(<span class=\"hljs-number\">1<\/span> row)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"summary\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<p>In this tutorial, you learned how to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Define the <code>products<\/code> table using the PostgreSQL <code>CREATE TABLE<\/code> statement.<\/li>\n\n\n\n<li>Connect to PostgreSQL from Python using <code>psycopg.connect()<\/code>.<\/li>\n\n\n\n<li>Execute a <code>CREATE TABLE<\/code> statement with <code>cur.execute()<\/code>.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"2642\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-python\/create-table\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL Python: Create Table\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"2642\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-python\/create-table\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL Python: Create Table\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Summary: In this tutorial, you&#8217;ll learn how to create a table in PostgreSQL from Python using Psycopg 3. Prerequisites # Before you start, make sure you have: What the products table stores # The products table stores basic information: Here&#8217;s the statement for creating the products table in PostgreSQL: Python script for creating tables # [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2630,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2642","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PostgreSQL Python: Create Table<\/title>\n<meta name=\"description\" content=\"In this tutorial, you&#039;ll learn how to create a table in PostgreSQL from Python using Psycopg 3.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pgtutorial.com\/postgresql-python\/create-table\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL Python: Create Table\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you&#039;ll learn how to create a table in PostgreSQL from Python using Psycopg 3.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pgtutorial.com\/postgresql-python\/create-table\/\" \/>\n<meta property=\"og:site_name\" content=\"PostgreSQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-11T03:07:05+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-python\\\/create-table\\\/\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-python\\\/create-table\\\/\",\"name\":\"PostgreSQL Python: Create Table\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\"},\"datePublished\":\"2026-04-11T02:02:26+00:00\",\"dateModified\":\"2026-04-11T03:07:05+00:00\",\"description\":\"In this tutorial, you'll learn how to create a table in PostgreSQL from Python using Psycopg 3.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-python\\\/create-table\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-python\\\/create-table\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-python\\\/create-table\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL Python\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-python\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PostgreSQL Python: Create Table\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/\",\"name\":\"PostgreSQL Tutorial\",\"description\":\"Learn PostgreSQL from Scratch\",\"alternateName\":\"PostgreSQL\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pgtutorial.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PostgreSQL Python: Create Table","description":"In this tutorial, you'll learn how to create a table in PostgreSQL from Python using Psycopg 3.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pgtutorial.com\/postgresql-python\/create-table\/","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL Python: Create Table","og_description":"In this tutorial, you'll learn how to create a table in PostgreSQL from Python using Psycopg 3.","og_url":"https:\/\/www.pgtutorial.com\/postgresql-python\/create-table\/","og_site_name":"PostgreSQL Tutorial","article_modified_time":"2026-04-11T03:07:05+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pgtutorial.com\/postgresql-python\/create-table\/","url":"https:\/\/www.pgtutorial.com\/postgresql-python\/create-table\/","name":"PostgreSQL Python: Create Table","isPartOf":{"@id":"https:\/\/www.pgtutorial.com\/#website"},"datePublished":"2026-04-11T02:02:26+00:00","dateModified":"2026-04-11T03:07:05+00:00","description":"In this tutorial, you'll learn how to create a table in PostgreSQL from Python using Psycopg 3.","breadcrumb":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-python\/create-table\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pgtutorial.com\/postgresql-python\/create-table\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pgtutorial.com\/postgresql-python\/create-table\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL Python","item":"https:\/\/www.pgtutorial.com\/postgresql-python\/"},{"@type":"ListItem","position":3,"name":"PostgreSQL Python: Create Table"}]},{"@type":"WebSite","@id":"https:\/\/www.pgtutorial.com\/#website","url":"https:\/\/www.pgtutorial.com\/","name":"PostgreSQL Tutorial","description":"Learn PostgreSQL from Scratch","alternateName":"PostgreSQL","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pgtutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2642","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/comments?post=2642"}],"version-history":[{"count":3,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2642\/revisions"}],"predecessor-version":[{"id":2646,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2642\/revisions\/2646"}],"up":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2630"}],"wp:attachment":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/media?parent=2642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}