<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Ok solved it.</p>
<p>What I was trying to do was simply to copy a csv into a Postgres
database. (db and schema already existing, not the table)<br>
</p>
<p><br>
</p>
<p>The problem was (in terminal)<br>
</p>
<p>old way :<br>
</p>
<p> ogr2ogr PG:"dbname='insee' port=5432 host='localhost'
user='thomas' password='xxxxxxxx' schemas='wip'" test_file.csv </p>
<p>works</p>
<p><br>
</p>
<p>new way :<br>
</p>
<p>gdal vector convert test_file.csv PG:"dbname='insee' port=5432
host='localhost' user='thomas' password='xxxxxxxx' schemas='wip'"
<br>
</p>
<p>don't work, I need to add the --append option, even to create the
table from scratch (but is that the intended way ?)</p>
<p><br>
</p>
<p>Another problem was that with the Python API, with the :</p>
<p>format=PostgreSQL option</p>
<p>it won't be enough, I still need to specify PG: before my
connection string or gdal will search for a file or directory
named as the connection string.</p>
<p><br>
</p>
<p>Thanks a lot !<br>
</p>
<p><br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">Le 22/08/2025 à 19:21, Even Rouault a
écrit :<br>
</div>
<blockquote type="cite"
cite="mid:7d132d33-c996-4e06-a712-971f00851df8@spatialys.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<p>Thomas,</p>
<p>are you sure you really used --overwrite in the terminal and
not --overwrite-layer ? The latter one is the one you want to
use in this scenario of opening an existing datasource and
overwriting its layer. And in python this will be
overwrite_layer=True</p>
<p>Even<br>
</p>
<div class="moz-cite-prefix">Le 22/08/2025 à 19:13, Thomas
Szczurek-Gayant via gdal-dev a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:e1006e5d-7006-439a-9cfb-f3583b6161d4@gmail.com">
<meta http-equiv="content-type"
content="text/html; charset=UTF-8">
<p>Hi,</p>
<p><br>
</p>
<p>I've a question with the python API of gdal 3.11 new programs
and PostgreSQL driver.</p>
<p><br>
</p>
<p>I can run this in a terminal<br>
</p>
<p><span style="font-family:monospace">gdal vector convert
--overwrite base-cc-evol-struct-pop.csv PG:"dbname='insee'
port=5432 host='localhost' user='thomas' password='xxxxxx'
schemas='wip' tables='rp_population_import'"<br>
<span style="color:#000000;background-color:#ffffff;"> </span><br>
</span> and everything is working fine.</p>
<p>But if I try from the python API with <br>
</p>
<p>gdal.Run("vector", "convert", format="PostgreSQL",
overwrite=True, input="base-cc-evol-struct-pop.csv",
output="dbname='insee' port=5432 host='localhost'
user='thomas' password='xxxxxxxx' schemas='wip'
tables='rp_population_import'")<br>
</p>
<p>Python throw this error as if gdal/postgres actually try to
create a new db:</p>
<p>ERROR 1: PostgreSQL driver doesn't currently support database
creation.<br>
Please create database with the `createdb' command.<br>
ERROR 1: PostgreSQL driver failed to create dbname='insee'
port=5432 host='localhost' user='thomas' password=XXXXXXXXXXXX
schemas='wip' tables='rp_population_import'<br>
Traceback (most recent call last):<br>
File "/home/thomas/repos_git/bd_insee/python/__main__.py",
line 63, in <module><br>
gdal.Run("vector", "convert", format="PostgreSQL",
overwrite=True, input="base-cc-evol-struct-pop.csv",
output="dbname='insee' port=5432 host='localhost'
user='thomas' password='xxxxxx' schemas='wip'
tables='rp_population_import'")<br>
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>
File
"/home/thomas/miniforge3/envs/bd_insee/lib/python3.13/site-packages/osgeo/gdal.py",
line 3353, in Run<br>
raise RuntimeError("Algorithm.Run() failed: %s" %
GetLastErrorMsg())<br>
RuntimeError: Algorithm.Run() failed: PostgreSQL driver failed
to create dbname='insee' port=5432 host='localhost'
user='thomas' password=XXXXXXXXXXXX schemas='wip'
tables='rp_population_import'</p>
<p><br>
</p>
<p>Does anyone have a clue or it's me doing it bad ?</p>
<p>Thanks !<br>
</p>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
gdal-dev mailing list
<a class="moz-txt-link-abbreviated moz-txt-link-freetext"
href="mailto:gdal-dev@lists.osgeo.org" moz-do-not-send="true">gdal-dev@lists.osgeo.org</a>
<a class="moz-txt-link-freetext"
href="https://lists.osgeo.org/mailman/listinfo/gdal-dev"
moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
</pre>
</blockquote>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.spatialys.com"
moz-do-not-send="true">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</blockquote>
</body>
</html>