Postgre RAISE NOTICE and PHP

Started by Andre Lopesover 16 years ago15 messagesgeneral
Jump to latest
#1Andre Lopes
lopes80andre@gmail.com

Hi,

I'm developing a function with some checks, for example... to check if the
e-mail is valid or not.

If the e-mail is not valid I put a line with RAISE NOTICE 'E-mail not
valid'.

I need to know if it is possible to show this RAISE NOTICE when I run this
function from PHP.

Best Regards,
André.

#2Randal L. Schwartz
merlyn@stonehenge.com
In reply to: Andre Lopes (#1)
Re: Postgre RAISE NOTICE and PHP

"Andre" == Andre Lopes <lopes80andre@gmail.com> writes:

Andre> I'm developing a function with some checks, for example... to check if the
Andre> e-mail is valid or not.

How are you hoping to do this? The regex to validate an email
address syntactically is pretty large:

http://ex-parrot.com/~pdw/Mail-RFC822-Address.html

And no, I'm not kidding. If your regex is smaller than that, you aren't
validating email... you're validating something "kinda like email".

For example, <fred&barney@stonehenge.com> is a valid email address. (Go
ahead, try it... it has an autoresponder.)

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/&gt;
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

#3Scott Marlowe
scott.marlowe@gmail.com
In reply to: Andre Lopes (#1)
Re: Postgre RAISE NOTICE and PHP

On Tue, Aug 18, 2009 at 10:57 AM, Andre Lopes<lopes80andre@gmail.com> wrote:

Hi,

I'm developing a function with some checks, for example... to check if the
e-mail is valid or not.

If the e-mail is not valid I put a line with RAISE NOTICE 'E-mail not
valid'.

I need to know if it is possible to show this RAISE NOTICE when I run this
function from PHP.

http://www.php.net/manual/en/function.pg-last-notice.php

example plpgsql function:
create or replace function tester() returns int language plpgsql as $$
BEGIN
raise notice 'whoops';
return 1;
END
$$;

example php:
<?php
$conn = pg_connect("dbname=smarlowe");
$res = pg_query("select tester()");
print pg_last_notice($conn);
print "\n";
?>

#4Adam Rich
adam.r@sbcglobal.net
In reply to: Andre Lopes (#1)
Re: Postgre RAISE NOTICE and PHP

Andre,
See this PHP page:

http://www.php.net/manual/en/function.pg-last-notice.php

Andre Lopes wrote:

Show quoted text

Hi,

I'm developing a function with some checks, for example... to check if
the e-mail is valid or not.

If the e-mail is not valid I put a line with RAISE NOTICE 'E-mail not
valid'.

I need to know if it is possible to show this RAISE NOTICE when I run
this function from PHP.

Best Regards,
Andr�.

#5Clemens Schwaighofer
clemens_schwaighofer@e-gra.co.jp
In reply to: Randal L. Schwartz (#2)
Re: Postgre RAISE NOTICE and PHP

On Wed, Aug 19, 2009 at 02:11, Randal L. Schwartz<merlyn@stonehenge.com> wrote:

"Andre" == Andre Lopes <lopes80andre@gmail.com> writes:

Andre> I'm developing a function with some checks, for example... to check if the
Andre> e-mail is valid or not.

How are you hoping to do this?  The regex to validate an email
address syntactically is pretty large:

 http://ex-parrot.com/~pdw/Mail-RFC822-Address.html

And no, I'm not kidding.  If your regex is smaller than that, you aren't
validating email... you're validating something "kinda like email".

Just in my opinion, this regex is completely too large. For basic
validating something like:
^[A-Za-z0-9!#$%&'*+-\/=?^_`{|}~][A-Za-z0-9!#$%&'*+-\/=?^_`{|}~\.]{0,63}@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,4}){1}$
works very well

For example, <fred&barney@stonehenge.com> is a valid email address.  (Go
ahead, try it... it has an autoresponder.)

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

--
★ Clemens 呉 Schwaighofer
★ IT Engineer/Web Producer/Planning
★ E-Graphics Communications SP Digital
★ 6-17-2 Ginza Chuo-ku, Tokyo 104-8167, JAPAN
★ Tel: +81-(0)3-3545-7706
★ Fax: +81-(0)3-3545-7343
http://www.e-gra.co.jp
This e-mail is intended only for the named person or entity to which it is addressed and contains valuable business information that is privileged, confidential and/or otherwise protected from disclosure. If you received this e-mail in error, any review, use, dissemination, distribution or copying of this e-mail is strictly prohibited. Please notify us immediately of the error via e-mail to disclaimer@tbwaworld.com and please delete the e-mail from your system, retaining no copies in any media. We appreciate your cooperation.

#6Michael Glaesemann
grzm@seespotcode.net
In reply to: Scott Marlowe (#3)
Re: Postgre RAISE NOTICE and PHP

On Aug 18, 2009, at 16:45 , Scott Marlowe wrote:

On Tue, Aug 18, 2009 at 10:57 AM, Andre
Lopes<lopes80andre@gmail.com> wrote:

I need to know if it is possible to show this RAISE NOTICE when I
run this
function from PHP.

http://www.php.net/manual/en/function.pg-last-notice.php

Thanks, Scott.

Is there an equivalent in PDO? Looking through the docs I don't see
one. It'd also be nice to be able to get at any/all of the additional
information that's passed back: warning, context, hint, etc.

Michael Glaesemann
grzm seespotcode net

#7Randal L. Schwartz
merlyn@stonehenge.com
In reply to: Clemens Schwaighofer (#5)
Re: Postgre RAISE NOTICE and PHP

"Clemens" == Clemens Schwaighofer <clemens_schwaighofer@e-gra.co.jp> writes:

Clemens> Just in my opinion, this regex is completely too large. For basic
Clemens> validating something like:
Clemens> ^[A-Za-z0-9!#$%&'*+-\/=?^_`{|}~][A-Za-z0-9!#$%&'*+-\/=?^_`{|}~\.]{0,63}@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,4}){1}$
Clemens> works very well

Fails on ".mobile" TLD. Has a pointless {1} in it, which does
absolutely nothing, providing that the creator of the regex was already
missing a few clues.

That's the problem with these kinds of regex... you test it on what
you know, but you're not consulting the *actual* *internet* specifications
(which have been readily available since the dawn of Internet time).

Either use the regex I pointed to already, or stay with the simpler:

/\S.*@.*\S/

which will at least not deny anyone with a *perfectly legitimate* email
address from making it into your system.

Or, use your regex *only* in an *advice* category, with the ability
for the user to say "yes, I'm really sure this is my address".

Please, for the sake of the net, do the Right Thing here. This is
what I'm arguing for. Anything less than that, and your code deserves
to end up in thedailywtf.com as an example of what *not* to do.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/&gt;
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

#8Scott Marlowe
scott.marlowe@gmail.com
In reply to: Randal L. Schwartz (#7)
Re: Postgre RAISE NOTICE and PHP

On Wed, Aug 19, 2009 at 8:41 AM, Randal L.
Schwartz<merlyn@stonehenge.com> wrote:

"Clemens" == Clemens Schwaighofer <clemens_schwaighofer@e-gra.co.jp> writes:

Clemens> Just in my opinion, this regex is completely too large. For basic
Clemens> validating something like:
Clemens> ^[A-Za-z0-9!#$%&'*+-\/=?^_`{|}~][A-Za-z0-9!#$%&'*+-\/=?^_`{|}~\.]{0,63}@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,4}){1}$
Clemens> works very well

Fails on ".mobile" TLD.  Has a pointless {1} in it, which does
absolutely nothing, providing that the creator of the regex was already
missing a few clues.

Remonds me of the saying that for every complex problem there is a
simple, elegant and incorrect solution.

#9David Fetter
david@fetter.org
In reply to: Scott Marlowe (#8)
Re: Postgre RAISE NOTICE and PHP

On Wed, Aug 19, 2009 at 11:57:45AM -0600, Scott Marlowe wrote:

On Wed, Aug 19, 2009 at 8:41 AM, Randal L.
Schwartz<merlyn@stonehenge.com> wrote:

"Clemens" == Clemens Schwaighofer <clemens_schwaighofer@e-gra.co.jp> writes:

Clemens> Just in my opinion, this regex is completely too large. For basic
Clemens> validating something like:
Clemens> ^[A-Za-z0-9!#$%&'*+-\/=?^_`{|}~][A-Za-z0-9!#$%&'*+-\/=?^_`{|}~\.]{0,63}@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,4}){1}$
Clemens> works very well

Fails on ".mobile" TLD. �Has a pointless {1} in it, which does
absolutely nothing, providing that the creator of the regex was already
missing a few clues.

Remonds me of the saying that for every complex problem there is a
simple, elegant and incorrect solution.

That's from H. L. Mencken.

For every complex problem, there is an answer which is clear,
simple, and wrong.

Cheers,
David.
--
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david.fetter@gmail.com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

#10Clemens Schwaighofer
clemens_schwaighofer@e-gra.co.jp
In reply to: Randal L. Schwartz (#7)
Re: Postgre RAISE NOTICE and PHP

On 08/19/2009 11:41 PM, Randal L. Schwartz wrote:

"Clemens" == Clemens Schwaighofer <clemens_schwaighofer@e-gra.co.jp> writes:

Clemens> Just in my opinion, this regex is completely too large. For basic
Clemens> validating something like:
Clemens> ^[A-Za-z0-9!#$%&'*+-\/=?^_`{|}~][A-Za-z0-9!#$%&'*+-\/=?^_`{|}~\.]{0,63}@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,4}){1}$
Clemens> works very well

Fails on ".mobile" TLD. Has a pointless {1} in it, which does
absolutely nothing, providing that the creator of the regex was already
missing a few clues.

That's the problem with these kinds of regex... you test it on what
you know, but you're not consulting the *actual* *internet* specifications
(which have been readily available since the dawn of Internet time).

Either use the regex I pointed to already, or stay with the simpler:

/\S.*@.*\S/

which will at least not deny anyone with a *perfectly legitimate* email
address from making it into your system.

Or, use your regex *only* in an *advice* category, with the ability
for the user to say "yes, I'm really sure this is my address".

Please, for the sake of the net, do the Right Thing here. This is
what I'm arguing for. Anything less than that, and your code deserves
to end up in thedailywtf.com as an example of what *not* to do.

I am not going to defend any regex here, but in my opinion it helps on
what I want to see in email addresses.
Yes it fails on mobile, but I have not yet seen one. Probably the best
thing is to test nothing at all. Just accept it ...

--
[ Clemens Schwaighofer -----=====:::::~ ]
[ IT Engineer/Web Producer/Planning ]
[ E-Graphics Communications SP Digital ]
[ 6-17-2 Ginza Chuo-ku, Tokyo 104-8167, JAPAN ]
[ Tel: +81-(0)3-3545-7706 Fax: +81-(0)3-3545-7343 ]
[ http://www.e-gra.co.jp ]

#11Randal L. Schwartz
merlyn@stonehenge.com
In reply to: Clemens Schwaighofer (#10)
Re: Postgre RAISE NOTICE and PHP

"Clemens" == Clemens Schwaighofer <clemens_schwaighofer@e-gra.co.jp> writes:

Clemens> I am not going to defend any regex here, but in my opinion it helps on
Clemens> what I want to see in email addresses.
Clemens> Yes it fails on mobile, but I have not yet seen one.

And that's the problem. You get near-sighted if you put up a strong
validation for only things that *you* have seen. Because, guess what,
nobody outside your narrow view can sign up or be a customer.

Bad for business.

Clemens> Probably the best
Clemens> thing is to test nothing at all. Just accept it ...

Exactly! If you don't want to use the 950-character regex, DON'T DO
ANYTHING AT ALL. Far simpler.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/&gt;
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

#12Jasen Betts
jasen@xnet.co.nz
In reply to: Andre Lopes (#1)
Re: Postgre RAISE NOTICE and PHP

On 2009-08-19, Clemens Schwaighofer <clemens_schwaighofer@e-gra.co.jp> wrote:

On Wed, Aug 19, 2009 at 02:11, Randal L. Schwartz<merlyn@stonehenge.com> wrote:

"Andre" == Andre Lopes <lopes80andre@gmail.com> writes:

Andre> I'm developing a function with some checks, for example... to check if the
Andre> e-mail is valid or not.

How are you hoping to do this?  The regex to validate an email
address syntactically is pretty large:

 http://ex-parrot.com/~pdw/Mail-RFC822-Address.html

And no, I'm not kidding.  If your regex is smaller than that, you aren't
validating email... you're validating something "kinda like email".

Just in my opinion, this regex is completely too large. For basic
validating something like:
^[A-Za-z0-9!#$%&'*+-\/=?^_`{|}~][A-Za-z0-9!#$%&'*+-\/=?^_`{|}~\.]{0,63}@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,4}){1}$
works very well

not good: eg:

fails this valid address* : admin@xxxxxxx.museum
accepts this invalid one : you@gmail..com

"musedoma" replaced with several x to protect the innocent from spam

in some contexts email adrresses with no domain part are valid
addresses with [bracketed] mx servers instead of a domain and/or bang
paths are also allowed (but not in common use and often not desirable)

#13Jasen Betts
jasen@xnet.co.nz
In reply to: Andre Lopes (#1)
Re: Postgre RAISE NOTICE and PHP

On 2009-08-20, Randal L. Schwartz <merlyn@stonehenge.com> wrote:

"Clemens" == Clemens Schwaighofer <clemens_schwaighofer@e-gra.co.jp> writes:

Clemens> I am not going to defend any regex here, but in my opinion it helps on
Clemens> what I want to see in email addresses.
Clemens> Yes it fails on mobile, but I have not yet seen one.

And that's the problem. You get near-sighted if you put up a strong
validation for only things that *you* have seen. Because, guess what,
nobody outside your narrow view can sign up or be a customer.

Bad for business.

Clemens> Probably the best
Clemens> thing is to test nothing at all. Just accept it ...

Exactly! If you don't want to use the 950-character regex, DON'T DO
ANYTHING AT ALL. Far simpler.

Or do an MX lookup on the domain part (or a partial attempt to route
mail*) before sending it to the database.

*contact the domains MX and in SMTP go as far as "RCPT TO: ... " and
then send "QUIT" after it is accepted or refused.

#14Sam Mason
sam@samason.me.uk
In reply to: Jasen Betts (#13)
Re: Postgre RAISE NOTICE and PHP

On Thu, Aug 20, 2009 at 01:03:47PM +0000, Jasen Betts wrote:

On 2009-08-20, Randal L. Schwartz <merlyn@stonehenge.com> wrote:

Exactly! If you don't want to use the 950-character regex, DON'T DO
ANYTHING AT ALL. Far simpler.

Or do an MX lookup on the domain part (or a partial attempt to route
mail*) before sending it to the database.

*contact the domains MX and in SMTP go as far as "RCPT TO: ... " and
then send "QUIT" after it is accepted or refused.

Why not just go the whole way and send an email asking for confirmation?
When you get a response you know the email address is actually useful
for contacting the user, rather than it being a typo and going somewhere
else.

--
Sam http://samason.me.uk/

#15Clemens Schwaighofer
clemens_schwaighofer@e-gra.co.jp
In reply to: Jasen Betts (#12)
Re: Postgre RAISE NOTICE and PHP

On Thu, Aug 20, 2009 at 21:52, Jasen Betts<jasen@xnet.co.nz> wrote:

On 2009-08-19, Clemens Schwaighofer <clemens_schwaighofer@e-gra.co.jp> wrote:

On Wed, Aug 19, 2009 at 02:11, Randal L. Schwartz<merlyn@stonehenge.com> wrote:

"Andre" == Andre Lopes <lopes80andre@gmail.com> writes:

Andre> I'm developing a function with some checks, for example... to check if the
Andre> e-mail is valid or not.

How are you hoping to do this?  The regex to validate an email
address syntactically is pretty large:

 http://ex-parrot.com/~pdw/Mail-RFC822-Address.html

And no, I'm not kidding.  If your regex is smaller than that, you aren't
validating email... you're validating something "kinda like email".

Just in my opinion, this regex is completely too large. For basic
validating something like:
^[A-Za-z0-9!#$%&'*+-\/=?^_`{|}~][A-Za-z0-9!#$%&'*+-\/=?^_`{|}~\.]{0,63}@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,4}){1}$
works very well

not good: eg:

fails this valid address* : admin@xxxxxxx.museum

yes it does, but all I need to change is {2,4}, to {2,6} or {2,}

accepts this invalid one  : you@gmail..com

and not it does not. I just tested it here.

The regex helps to avoid stuff like this:

foo]@bar.com
foo@@bar.com
foo@.bar.com
foo@bar

etc

"musedoma" replaced with several x to protect the innocent from spam

in some contexts email adrresses with no domain part are valid
addresses with [bracketed] mx servers instead of a domain and/or bang
paths are also allowed (but not in common use and often not desirable)

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

--
★ Clemens 呉 Schwaighofer
★ IT Engineer/Web Producer/Planning
★ E-Graphics Communications SP Digital
★ 6-17-2 Ginza Chuo-ku, Tokyo 104-8167, JAPAN
★ Tel: +81-(0)3-3545-7706
★ Fax: +81-(0)3-3545-7343
http://www.e-gra.co.jp
This e-mail is intended only for the named person or entity to which it is addressed and contains valuable business information that is privileged, confidential and/or otherwise protected from disclosure. If you received this e-mail in error, any review, use, dissemination, distribution or copying of this e-mail is strictly prohibited. Please notify us immediately of the error via e-mail to disclaimer@tbwaworld.com and please delete the e-mail from your system, retaining no copies in any media. We appreciate your cooperation.