3

Using Sybase IQ 12.5,

When I try to insert the result of a stored proc into a table like this:

INSERT mytable (column1, column2, column3)
SELECT column1, column2, column3
FROM (myproc('AAA'))

I get the following:

ASA Error -1001042: Table, 'mytable', is not accessible in this context. 

The Sybase website has no further explanation

Robert Brown
  • 10,888
  • 7
  • 34
  • 40

2 Answers2

1

Can you post the definition of your stored procedure? The test below was successful for me, though I used Sybase SQL Anywhere (I tried versions 12.0.1 and 11.0.1). The Sybase IQ server is based on the SQL Anywhere execution engine so this should be an equivalent test, though I'm unsure what version of SQL Anywhere corresponds to IQ 12.5.

create table mytable (column1 int, column2 int, column3 int);
create procedure myproc( parm varchar(10))
  result ( column1 int, column2 int, column3 int)
  begin
     select 1,2,3;
  end;
INSERT mytable (column1, column2, column3)
  SELECT column1, column2, column3
  FROM (myproc('AAA'));

Full disclosure: I work for Sybase in SQL Anywhere engineering.

Graeme Perrow
  • 56,086
  • 21
  • 82
  • 121
1

Problem was caused by my target table having a check constraint.

Here's an example to recreate the problem:

create table mytable (column1 int, 
    column2 int, 
    column3 int CHECK (column3 in (1,2,3)));

create procedure myproc( parm varchar(10))
  result ( column1 int, column2 int, column3 int)
  begin
     select 1,2,3;
 end;
INSERT mytable (column1, column2, column3)
  SELECT column1, column2, column3
  FROM (myproc('AAA'));
Robert Brown
  • 10,888
  • 7
  • 34
  • 40