Re: Fail to create distributed table in Citus

From: Chapman Flack <chap(at)anastigmatix(dot)net>
To: pljava-dev(at)lists(dot)postgresql(dot)org
Subject: Re: Fail to create distributed table in Citus
Date: 2020-11-19 18:54:04
Message-ID: 5FB6BF4C.3060209@anastigmatix.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pljava-dev

On 11/19/20 13:20, Erik Mata wrote:
> ...
> stmt.executeQuery("SELECT create_distributed_table('test1', 'a',
> colocate_with => 'none')");
> }
> ...
> I was wondering if it could be something with the single quotes surrounding
> the parameters, but I've tried to use double single quotes and also to
> escape the single quotes, but then it really fails with an error. Looking

No, that's fine the way you've written it, as long as those values are
constant strings as you've shown.

The times you want to be careful are when the parameters are being passed
to you and you don't know what characters they might contain. In those cases
you would typically use

ps = connection.prepareStatement(
"SELECT create_distributed_table(?, ?, colocate_with => ?)");
ps.setString(1, tableName);
ps.setString(2, columnName);
ps.setString(3, colocated);
ps.execute();

so the driver takes care of how to pass the parameters correctly.

With data-definition language like CREATE TABLE, it's a little different,
because it can't be prepared and parameterized like a DML statement.
Those are the cases where, if you were being passed the table name or
column name, you would have to be careful about constructing the
CREATE TABLE and using the right quoting rules, getting familiar with
Statement.enquoteIdentifier() or, even better,
org.postgresql.pljava.sqlgen.Lexicals.Identifier.deparse(). And there are
more tricks to getting that right than I should go into here, because
they're probably off-topic for this particular issue.

Regards,
-Chap

In response to

Browse pljava-dev by date

  From Date Subject
Next Message Chapman Flack 2021-10-11 17:52:37 PL/Java 1.6.3 and 1.5.8 released
Previous Message Erik Mata 2020-11-19 18:20:09 Re: Fail to create distributed table in Citus