Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Julia REPL mode for SQL

License

NotificationsYou must be signed in to change notification settings

c42f/SQLREPL.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Julia REPL mode for PostgreSQL powered byReplMaker.jl,LibPQ.jl andSQLStrings.jl.

Tutorial

Install the package with Julia's Pkg mode:

pkg> add SQLREPL

To connect the REPL mode, you'll need a connection string for your Postgresdatabase. You can then use:

julia>using SQLREPLjulia> SQLREPL.connect("your_connection_string")REPL mode SQL initialized. Press ) to enter and backspace to exit."Prompt(\"SQL>\",...)"

Now press) to enter the REPL mode. You can create tables and do some simpledata insertion and extraction with standard SQL syntax:

SQL> create table foo (xtext, yint);SQL>insert into foovalues ('hi',1);SQL>insert into foovalues ('ho ho',2);SQL>select*from foo2×2 DataFrame Row │ x        y           │ String?  Int32? ─────┼─────────────────1 │ hi12 │ ho ho2

Thanks to SQLStrings.jl, you can also interpolate local Julia values into yourexpression. Let's setmin_y in the JuliaMain module:

julia> min_y=2

And we can now use$min_y within our queries:

SQL>select*from foowhere y>= $min_y1×2 DataFrame Row │ x        y           │ String?  Int32? ─────┼─────────────────1 │ ho ho2

For more complex data manipulation, the REPL mode can be combined withprogrammatic access via the normal Julia REPL:

julia>using LibPQ, SQLStringsjulia> conn= LibPQ.Connection("");julia>for y=1:10           msg="Hi$y"           LibPQ.execute(conn,sql`insert into foo values ($msg,$y)`)end

thence

SQL>select*from foo12×2 DataFrame Row │ x        y           │ String?  Int32? ─────┼─────────────────1 │ hi12 │ ho ho23 │ Hi114 │ Hi225 │ Hi336 │ Hi447 │ Hi558 │ Hi669 │ Hi7710 │ Hi8811 │ Hi9912 │ Hi1010

How To

Editing multi-line statements

To edit multi-line SQL statements easily, surround your statement with brackets:

SQL> (select*from foowhere y>5and   y<=7)2×2 DataFrame Row │ x        y           │ String?  Int32? ─────┼─────────────────1 │ Hi662 │ Hi77

Alternatively, to insert a line, the usual key bindingALT+Enter can always be used.

Accessing the result of the previous query

The resultingDataFrame is available in theans variable back in the JuliaREPL. Starting with

SQL> (select*from foowhere y>5and   y<=7);

we then have

julia> ans2×2 DataFrame Row │ x        y           │ String?  Int32? ─────┼─────────────────1 │ Hi662 │ Hi77

Inspecting table schema

To inspect table schema you can use thepsql-like meta-command\d:

SQL> \d foo2×5 DataFrame Row │ column_name  data_type  character_maximum_length  column_default  is_nullable      │ String?      String?Union{Missing, Int32}     String?         String?     ─────┼───────────────────────────────────────────────────────────────────────────────1 │ xtext                        missing  missing         YES2 │ yinteger                     missing  missing         YES

In the future we might implement more of thepsql meta-commands.

Development

Build Status

This package arose froma discussion on Julia discourse.

About

A Julia REPL mode for SQL

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp