Re: Extract especific text from a sql statement

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Extract especific text from a sql statement
Date: 2014-10-01 15:56:43
Message-ID: 1412179003135-5821296.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Emanuel Araújo wrote
> Hi,
>
> I need help to extract fields and tables from a sql statement.
>
> Example:
>
> SELECT pc.cod, pc.val, pi.qtd,
> COALESCE(pc.name, 'empty') AS name, lower(coalesce(pc.email, 'empty')) as
> email,
> status
> FROM pc
> INNER JOIN pi on (pc.cod = pi.cod)
> WHERE pc.startdate > CURRENT_DATE
> order by 1 desc
> ;
>
> I need to return that:
>
> pc.cod
> pc.val
> pi.qtd
> pc.name
> pc.email
> status
> pc
> pi
> pc.startdate
>
>
>
> can you help me ?

Me, probably not. I would suggest you tell us what goal/use-case you have
in mind that you think you need to do the above.

The project is open source so you are welcome to look at the parser code and
see how it goes about pulling out identifiers and determining what they are.

A big question is how do you want to deal with aliases and views present in
the query?

Do you have a particular language you are restricting your search to?

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Extract-especific-text-from-a-sql-statement-tp5821256p5821296.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jonathan Vanasco 2014-10-01 16:12:33 Re: improving speed of query that uses a multi-column "filter" ?
Previous Message Adam Brusselback 2014-10-01 15:09:15 Re: table versioning approach (not auditing)