1

I have tried to insert this data into my table in postgres, but i get this error: ERROR: syntax error at or near "left" The following is my insert and the following parameters...

public static void Add(int i, int p) throws SQLException{
    String path = p + "/";

    st = "INSERT INTO melvin_ifis_network (link_id, length, area, up_area, elevation, links_drop, longest_channel_length, to_border, left, right, parent_link, travel_time07, layer, ial, ia_connected, h_order, ia_outlet, branch_layer, memory, branch, model) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    state = connection.prepareStatement(st);
    state.setInt(1, i);
    state.setInt(2, 0);
    state.setInt(3, 0);
    state.setInt(4, 0);
    state.setInt(5, 0);
    state.setInt(6, 0);
    state.setInt(7, 0);
    state.setInt(8, 0);
    state.setInt(9, 0);
    state.setInt(10, 0);
    state.setInt(11, p);
    state.setDouble(12, 0.0);
    state.setInt(13, 0);
    state.setBoolean(14, true);
    state.setBoolean(15, true);
    state.setInt(16, 0);
    state.setBoolean(17, false);
    state.setInt(18, 0);
    state.setInt(19, 0);
    state.setInt(20, 0);
    state.setBoolean(21, true);
    state.executeUpdate();
}

2 Answers 2

2

left (and right) is a reserved word. You need to quote it: "left"

For more details on the rules about identifiers see the manual: http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

1

You are getting that error cause left, right are reserve word. You will have to escape them using double quote " " like "left" and "right"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.