cancel
Showing results for 
Search instead for 
Did you mean: 

Syntax error near 'unique' on line 1 on selecting quoted property

Former Member
0 Kudos
2,459

SYSIDX system view has a property called unique and in docs its quoted with double quotes unlike other properties. When I select unquoted properties everything is ok, no errors. But when I try to select the quoted one I get the following error. Therefore, I have a question: how to select this quoted properties?

Syntax error near 'property_name_here' on line 1

SYSIDX docs page

UPDATE

Query that causes error:

$query = sasql_query($conn,
    "SELECT st.table_name, stc.column_name, si.index_category, si.unique
    FROM sysidxcol sic
    INNER JOIN systab st ON st.table_id = sic.table_id
    INNER JOIN systabcol stc ON stc.column_id = sic.column_id
    INNER JOIN sysidx si ON si.index_id = sic.index_id
    WHERE st.table_id = stc.table_id
        AND si.table_id = sic.table_id
        AND st.table_id BETWEEN 691 AND 747"
);

Also tried this:

$query = sasql_query($conn,
    "SELECT st.table_name, stc.column_name, si.index_category, si.['unique']
    FROM sysidxcol sic
    INNER JOIN systab st ON st.table_id = sic.table_id
    INNER JOIN systabcol stc ON stc.column_id = sic.column_id
    INNER JOIN sysidx si ON si.index_id = sic.index_id
    WHERE st.table_id = stc.table_id
        AND si.table_id = sic.table_id
        AND st.table_id BETWEEN 691 AND 747"
);

But it gives the next error

sasql_query(): SQLAnywhere: [-143] Column ''unique'' not found
MarkCulp
Participant

Please show us the exact queries that you are using.

Note that the SYSIDX table has a column called unique but the word 'unique' is a keyword so it must be quoted (using double quotes) when used as an identifier. The table in the SYSIDX docs page is simply adding the double quotes around unique to indicate this fact.

Former Member
0 Kudos

Updated my question with queries from the code

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

Found a solution myself. Thanks for Mark Culp for speicfying direction to search my problem.

In order to select columns, which names are similar to a reserved SQL word, put square brackets around column name:

SELECT [column_name] FROM table_name
MarkCulp
Participant

Glad you found your solution. Note that you tried to use single quotes (') around the word and this resulted in your error. In SQL single quotes are used to construct a string. To construct an identified you need to use double quotes (") or, as you have discovered, use brackets []. You can read more about SQL identifiers here: http://dcx.sap.com/index.html#sqla170/en/html/8170eb5b6ce21014a7e1a2fd6b4a85fc.html and read about SQL strings here: http://dcx.sap.com/index.html#sqla170/en/html/817b3d006ce21014ad07f050c018135e.html

Answers (0)