Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / Sybase Topics / September 2008

Tip: Looking for answers? Try searching our database.

The name 'avail_seq' is illegal in this context

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
yawnmoth - 23 Sep 2008 17:59 GMT
INSERT INTO test_table (avail_seq) VALUES ((SELECT
COALESCE(MAX(avail_seq), 0) + 1 FROM test_table));

Whenever I run that SQL query, I get the following error:

The name 'avail_seq' is illegal in this context. Only constants,
constant expressions, or variables allowed here. Column names are
illegal. (severity 15, procedure N/A)

Here's my table definition:

create table test_table (
avail_seq            int           not null,

constraint test_table primary key (avail_seq)
)
grant all on test_table to public;

It seems to me like using IDENTITY would solve this, but alas, I
didn't create the table.

An alternative would be to do the SELECT subquery, by itself, and then
the INSERT, later, but that wouldn't be atomic.

In MySQL, I could use transactions.  ie.

BEGIN;
@avail_seq = SELECT COALESCE(MAX(avail_seq), 0) + 1 FROM test_table;
INSERT INTO test_table (avail_seq) VALUES (@avail_seq);
COMMIT;

Or something like that.  Unfortunately, I'm not sure how to do that
with Sybase.

Any ideas?
Bret_Halford - 23 Sep 2008 18:50 GMT
Write it without the VALUES keyword:

insert into test_table (avail_seq) select COALESCE(MAX(avail_seq), 0)
+ 1 FROM test_table
yawnmoth - 25 Sep 2008 23:57 GMT
> Write it without the VALUES keyword:
>
>  insert into test_table (avail_seq) select COALESCE(MAX(avail_seq), 0)
> + 1 FROM test_table

That worked - thanks!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.