0

I am trying to insert some data in a hash distributed table which I created using Citus. And in Pyspark I am using JDBC postgres drives to insert data into tables. code which I am using to insert data into tables using JDBC in pyspark is:

    url = "jdbc:postgresql://host:port/db_name?rewriteBatchedStatements=true"
    properties = {"user":"user_name","password":"password"}
    df = spark.createDataFrame(rdd_name)
    df.write.jdbc(url=url, table="table_name", mode="append", properties=properties)

With this setup I am getting this error:

: org.postgresql.util.PSQLException: ERROR: relation "table_name" already exists
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2155)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:288)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:430)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:356)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:303)
at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:289)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:266)
at org.postgresql.jdbc.PgStatement.executeUpdate(PgStatement.java:246)
at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$.createTable(JdbcUtils.scala:692)
at org.apache.spark.sql.execution.datasources.jdbc.JdbcRelationProvider.createRelation(JdbcRelationProvider.scala:89)
at org.apache.spark.sql.execution.datasources.DataSource.write(DataSource.scala:426)
at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:215)
at org.apache.spark.sql.DataFrameWriter.jdbc(DataFrameWriter.scala:446)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:280)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:214)
at java.lang.Thread.run(Thread.java:745)

Can someone please help me how do I insert data into citus postgres using jdbc in pyspark? Thanks in advance.

Yaron
  • 10,166
  • 9
  • 45
  • 65
divya nagar
  • 33
  • 1
  • 6

1 Answers1

1

Your error message says that "table_name" already exists. Most likely, your code or framework is trying to create the same table again. Could you check that?

metdos
  • 13,411
  • 17
  • 77
  • 120