Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Perl 6 Junctions and Postgres SQL

by mugwumpjism (Hermit)
on Dec 21, 2007 at 22:02 UTC ( [id://658551]=perlmeditation: print w/replies, xml ) Need Help??

I noticed that PostgreSQL and Perl 6 have the same syntax for junctions (well, at least any)

samv=# select s from generate_series(1,20) s where s = any (select y f +rom generate_series(18,23) y) ; s ---- 18 19 20 (3 rows)

This year's perl:

perl -MPerl6::Junction=any -le 'for my $s (1..20) { if ($s == any(18..23) ) { print $s } }'

$h=$ENV{HOME};my@q=split/\n\n/,`cat $h/.quotes`;$s="$h/." ."signature";$t=`cat $s`;print$t,"\n",$q[rand($#q)],"\n";

Replies are listed 'Best First'.
Re: Perl 6 Junctions and Postgres SQL
by dragonchild (Archbishop) on Dec 22, 2007 at 15:10 UTC
    In other words, PostgreSQL provides an alias for "WHERE s IN (...)" and calls it "WHERE s = ANY(...)". Forgive me for being underwhelmed.

    It's not surprising that SQL is going to look at a lot like the junction operators - both operate on sets*. A relational database is nothing more than a set theory machine. The junction operators are similar. You even have all() and one() in SQL; they're just not in the forms you're thinking of.

    *: Yes, the junction operators deal with lists, but they treat the lists as sets.


    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

      I share your sentiments. Still, all is not lost. I was happy to hear of the generate_series thing. I don't know how directly this can be transposed to another DB, (thinking of Oracle here), but I do know that at times it can be nice to have a select generate a huge amount of arbitary data on the fly.

      The other day I needed to blend the numbers 1..19999 into a select, and after considering a select ... union select from dual for about a microsecond, I created a table with a single column containing the numbers from 1 to 19999. Sort of ugly, but it got the job done.

      • another intruder with the mooring in the heart of the Perl

Re: Perl 6 Junctions and Postgres SQL
by perlostitute (Initiate) on Dec 21, 2007 at 22:57 UTC

    How so?

      Ok, piece by piece:

      (select y from generate_series(18,23) y) (select s from generate_series(1,20) s)

      Is similar to, respectively:

      (18..23) (1..20)

      Then this query:

      select s from (1..20) where s = any( 18..23 )

      Is similar in meaning to this:

      for my $s (1..20) { if ($s == any(18..23) ) { print $s; } }

      Or, more close in expression to the SQL, the Perl 6:

      [1..20].grep:{ $_ == any(18..23) }.say

      Hmm, wouldn't it be useful to have a LINQ to Hyper-operator/Junction cheat-sheet...

      $h=$ENV{HOME};my@q=split/\n\n/,`cat $h/.quotes`;$s="$h/." ."signature";$t=`cat $s`;print$t,"\n",$q[rand($#q)],"\n";
        Toying with perl 5.10:
        perl -E 'for(1..20) { when([18..23]) { say } }'
        :-)

        I'm slightly puzzled that I couldn't write when(18..23), though.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://658551]
Approved by kyle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-19 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found