pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Regex
4+ messages / 3 participants
[nested] [flat]

* Regex
@ 1998-12-29 23:32  John C Cusick <jcc2@juno.com>
  0 siblings, 0 replies; 4+ messages in thread

From: jcc2@juno.com @ 1998-12-29 23:32 UTC (permalink / raw)
  To: pgsql-sql

Hello Everyone and Happy Holidays;

Is there any guide or faq on using regular expressions
with PostgreSQL ??

Thanks
JC
___________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com/getjuno.html
or call Juno at (800) 654-JUNO [654-5866]



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Regex
@ 2004-10-06 00:52  Theo Galanakis <Theo.Galanakis@lonelyplanet.com.au>
  0 siblings, 1 reply; 4+ messages in thread

From: Theo Galanakis @ 2004-10-06 00:52 UTC (permalink / raw)
  To: pgsql-sql


I know this is not a regex forum, however I had great assistance last time
and thought I would ask, since the regex is looking through an SQL
statement.

I was trying to parse a SQL statement and get all the tables used. I'm
actually doing this in Cold Fusion.

I have gone as far as this 

(FROM | JOIN ).*(?<=INNER JOIN|LEFT JOIN|LEFT OUTER JOIN|AS|WHERE|ORDER BY)

I know I need to look for FROM or JOIN and get all text within INNER
JOIN,LEFT JOIN,LEFT OUTER JOIN,AS,WHERE,ORDER BY... there are various
others.

I have tried a forward reference however this does not work, I think it
needs to be between the .[^INNER JOIN|LEFT JOIN|LEFT OUT JOIN|AS|WHERE|ORDER
BY]* somehow!!!

Basically the regex should return TABLEA, TABLEB from:

Select * 
from TABLEA
Inner jon TABLEB on tableb.columna = tablea.columna

Cheers,
	Theo


______________________________________________________________________
This email, including attachments, is intended only for the addressee
and may be confidential, privileged and subject to copyright.  If you
have received this email in error, please advise the sender and delete
it.  If you are not the intended recipient of this email, you must not
use, copy or disclose its content to anyone.  You must not copy or 
communicate to others content that is confidential or subject to 
copyright, unless you have the consent of the content owner.

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Regex
@ 2004-10-06 03:36  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Theo Galanakis <Theo.Galanakis@lonelyplanet.com.au>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2004-10-06 03:36 UTC (permalink / raw)
  To: Theo Galanakis <Theo.Galanakis@lonelyplanet.com.au>; +Cc: pgsql-sql

Theo Galanakis <Theo.Galanakis@lonelyplanet.com.au> writes:
> Basically the regex should return TABLEA, TABLEB from:

> Select * 
> from TABLEA
> Inner jon TABLEB on tableb.columna = tablea.columna

You realize of course that this problem is mathematically impossible?
Regexes are less powerful than context-free grammars, and so it is a
certainty that there exist legal SQL statements that will fool any regex
that you invent for this purpose.

If you know that the SQL statements are coming from a query generator
that produces only a certain style of SQL code, then you might be able
to come up with a solution that works reliably for the output of that
query generator.  But I wonder if you wouldn't be better off bypassing
the parse-and-deparse hacking and tapping directly into the query
generator.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Regex
@ 2004-10-06 05:44  Theo Galanakis <Theo.Galanakis@lonelyplanet.com.au>
  0 siblings, 0 replies; 4+ messages in thread

From: Theo Galanakis @ 2004-10-06 05:44 UTC (permalink / raw)
  To: pgsql-sql; +Cc: Tom Lane <tgl@sss.pgh.pa.us>


Thanks Tom, 
	I attacked the issue another way which appears to work... 

	I used :

	explain select * from nodes left join node_names on
node_names.node_id = nodes.node_id

	which returned :

	query 
	  QUERY PLAN 
	1 Merge Right Join (cost=429.16..793.48 rows=4510 width=193) 
	2 Merge Cond: ("outer".node_id = "inner".node_id) 
	3 -> Index Scan using node_names_node_id_key on node_names
(cost=0.00..278.58 rows=			7253 width=110) 
	4 -> Sort (cost=429.16..438.89 rows=3894 width=83) 
	5 Sort Key: nodes.node_id 
	6 -> Seq Scan on nodes (cost=0.00..196.94 rows=3894 width=83) 
	
	and then programatically searched for lines that begin with :

	Seq Scan on #table_name#
	Index Scan using #indexname# on #table_name#

	obtaining the #table_name#

	Being : nodes, node_names

Theo

-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us] 
Sent: Wednesday, 6 October 2004 1:36 PM
To: Theo Galanakis
Cc: Pgsql-Sql@Postgresql. Org
Subject: Re: [SQL] Regex 


Theo Galanakis <Theo.Galanakis@lonelyplanet.com.au> writes:
> Basically the regex should return TABLEA, TABLEB from:

> Select *
> from TABLEA
> Inner jon TABLEB on tableb.columna = tablea.columna

You realize of course that this problem is mathematically impossible?
Regexes are less powerful than context-free grammars, and so it is a
certainty that there exist legal SQL statements that will fool any regex
that you invent for this purpose.

If you know that the SQL statements are coming from a query generator that
produces only a certain style of SQL code, then you might be able to come up
with a solution that works reliably for the output of that query generator.
But I wonder if you wouldn't be better off bypassing the parse-and-deparse
hacking and tapping directly into the query generator.

			regards, tom lane


______________________________________________________________________
This email, including attachments, is intended only for the addressee
and may be confidential, privileged and subject to copyright.  If you
have received this email in error, please advise the sender and delete
it.  If you are not the intended recipient of this email, you must not
use, copy or disclose its content to anyone.  You must not copy or 
communicate to others content that is confidential or subject to 
copyright, unless you have the consent of the content owner.

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2004-10-06 05:44 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-12-29 23:32 Regex John C Cusick <jcc2@juno.com>
2004-10-06 00:52 Regex Theo Galanakis <Theo.Galanakis@lonelyplanet.com.au>
2004-10-06 03:36 ` Tom Lane <tgl@sss.pgh.pa.us>
2004-10-06 05:44 Re: Regex Theo Galanakis <Theo.Galanakis@lonelyplanet.com.au>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox