question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

insert as select does not work with parameters mapping

See original GitHub issue

CrateDB version: 4.2.6

Problem description: Mapping parameters for prepared SQL statement failed for insert-as-select query

Steps to reproduce:

create table test (x int)

Table TEST created.

select x from test where x = :param (and set :param to any value)

ok

insert into test (x) select x from test where x = 123

ok

insert into test (x) select x from test where x = :param (and set :param to any value)

SQL Error: Индекс колонки вне диапазона: 1. Допустимые значения: 1..0 (Column index out of range: 1. Valid values: 1..0 - sorry, I dont know how to change language to engish)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
shm-dmitrycommented, Oct 15, 2020

@mfussenegger I using wrapper for JDBC (similar to JDBCTemplate) All parameters there passed using ?

My SQL looks like a (sorry - it was minor issue for me, there was more important problems, and I forget to save original SQL. At now I cant found it in logs)

INSERT INTO table1 (col1, col2, col3, col4)
SELECT a, b, ?, c
FROM table2
WHERE d = ?

And this request executes via

		try (var conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/", "crate", "")) {
			try (var stm = conn.prepareStatement("insert into test (x) select x from test where x = ?")) {
				stm.setObject(1, 1);
				stm.execute();
			}
		}

I tryed to reproduce this now - and all works fine … Maybe it related to #10650 ? I dont know. In about a week I will try to reproduce #10650 on test cluster, and I will check this also.

Sorry for disturbing

0reactions
mfusseneggercommented, Nov 5, 2020

@shm-dmitry thank you for the updated test case. We came up with a fix (https://github.com/crate/crate/pull/10742) which will be released with 4.3.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

INSERT INTO SELECT statement overview and examples
We can map the column between the source and destination table using the following query.
Read more >
EXECUTE SQL parameters mapping problem
I Have EXECUTE SQL Task and I am trying to insert some data into table with syntax: "INSERT INTO test. SELECT ?" Parameter...
Read more >
How to make an insert with a combination of a select and ...
I have a stored function which receives a number of parameters. Within the function, I need to INSERT a row into a table...
Read more >
URL Actions - Tableau Help
Create an email with a URL action · Deselect Encode Data Values that URLs Do Not Support · Select Allow Multiple Values via...
Read more >
INSERT INTO Statement | ClickHouse Docs
If a list of columns does not include all existing columns, ... must be specified in the end of query if SELECT clause...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found