The forum will be down for maintenance over the weekend of August 18-20, 2017. The forum will be shut down on the evening (EDT) of Friday, August 18. Downtime is unknown but may be up to two days. The forum will be restarted as soon as maintenance is complete.

I try to found some information about limitations of used a SELECT using FOR READ ONLY on subqueries (Ultralite), everytime i try this an error occurs:

Syntax error near 'FOR' [SQL Offset: 1735] SQLCODE=-131, ODB 3 STATE="4200"

Select example:

SELECT COUNT(*) as groupCount FROM (SELECT name FROM table FOR READ ONLY ) AS DS (name)

This really don't work? why?

asked 12 Mar '13, 09:41

Tadeu%20Araujo's gravatar image

Tadeu Araujo
66124
accept rate: 0%


Short answer: Subqueries can't be anything other than read-only, so FOR READ ONLY is superfluous.

The FOR READ ONLY clause is only allowed in an outer SELECT statement, not a subquery, because only a SELECT statement can be used to fetch and update rows in a cursor... in other words, FOR UPDATE and hence FOR READ ONLY make no sense on a subquery... so you'll get the same SQLCODE -131 if you run your query on a SQL Anywhere server.

Here are a couple of examples...

Could not execute statement.
Syntax error near 'READ' on line 5
SQLCODE=-131, ODBC 3 State="42000"
Line 1, column 1

SELECT *
  FROM dummy
 WHERE dummy_col IN ( SELECT dummy_col
                        FROM dummy
                      FOR READ ONLY )

-----

Could not execute statement.
Syntax error near 'UPDATE' on line 5
SQLCODE=-131, ODBC 3 State="42000"
Line 1, column 1

SELECT *
  FROM dummy
 WHERE dummy_col IN ( SELECT dummy_col
                        FROM dummy
                      FOR UPDATE )

permanent link

answered 12 Mar '13, 10:10

Breck%20Carter's gravatar image

Breck Carter
26.6k433604877
accept rate: 21%

edited 12 Mar '13, 10:19

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×15

question asked: 12 Mar '13, 09:41

question was seen: 1,042 times

last updated: 12 Mar '13, 10:19