Skip to content

Error parsing Select statement: a column that uses a function with a parameter type of Select #605

Closed
@marcgise

Description

@marcgise

Actual Behavior

In PostgreSQL I have a view that one of the columns is the result of a query, and then converts it into an array, and then into a String:

SELECT p.id,
	pt.name,
	array_to_string(
		array(
			select pc.name
			from product_category pc
		), ','
	) AS categories
FROM product p;

The problem is the parameter of the 'array' function that is a query. If this parameter was for example an String, it works fine:

SELECT p.id,
	pt.name,
	array_to_string(
		array(
			'abc', 'def'
		), ','
	) AS categories
FROM product p;

Expected Behavior

The expected behavior is that the parser treats this parameter as an Statement of type Select

Steps to Reproduce the Problem

  1. Try to parse the given select
  2. The parser throws the exception:
net.sf.jsqlparser.JSQLParserException
	at net.sf.jsqlparser.parser.CCJSqlParserManager.parse(CCJSqlParserManager.java:40)
	at es.prodevelop.pui.model.db.ViewsAnalysis.init(ViewsAnalysis.java:130)
	at es.prodevelop.pui.model.db.ViewsAnalysis.access$0(ViewsAnalysis.java:99)
	at es.prodevelop.pui.model.db.ViewsAnalysis$1.run(ViewsAnalysis.java:90)
	at java.lang.Thread.run(Thread.java:748)
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered " "(" "( "" at line 3, column 17.
Was expecting one of:
    <EOF> 
    "AS" ...
    "DO" ...
    "ANY" ...
  1. Change the Select parameter into an String parameter, and try again, and it will work.

Specifications

  • Version: 1.1
  • Platform: Linux
  • Subsystem: Unbuntu 16.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions