Live data from Hacker News

Logica – Declarative logic programming language for data

logica.dev

61–67 of 67 posts

Re: Logica – Declarative logic programming language for data

#61

This is going to be a hell in production. Someone is going to write queries in this new language and then wonder why the produced MySQL queries in production take 45 minutes to execute.

There is a standard method of optimization - breaking predicate into smaller ones and saving intermediates into database.

Typically program runs efficiently, but when optimization is needed - you can do it by breaking up the predicate.

Re: Logica – Declarative logic programming language for data

#62

Earlier quoted context omitted.

I was turned off by this at first, but then tried it out. These are mistakes in the documentation. The tools just work with PostgreSQL and SQLite without any extra work.

How do you connect to an existing database so that you can query it? There are examples of how you can specify an "engine" which will create a new database and use it as a backend for executing queries but I want to query existing data in an sqlite database.

To connect to a database file use:

  @AttachDatabase("db_prefix", "your_file.db");
  # Then you can query from it:
  Q(..r) :- db_prefix.YourTable(..r);

Re: Logica – Declarative logic programming language for data

#63
post #7

Earlier quoted context omitted.

The syntax is Prolog-like, so people in the field are familiar with it.

Which field would that be? I.e. I understand now that it's seemingly about more than simple querying, so me coming very much from an analytics/ data crunching background am wondering what a use case would look like where this is arguably superior to SQL.

In my opinion any analytical query is easier to read in logic language than in SQL. But it's most obvious for recrusive querries. E.g. distance in graph defined by predicate (aka table) G written in Logica looke like:

  D(a, b) Min= 1 :- G(a, b);       # Connected by an edge => distance 1.
  D(a, c) Min= D(a, b) + D(b, c);  # Triangle inequality.
 
It will be much harder to read with SQL CTE. It can also computed over weighted graphs, which is impossible or extremely hard with SQL.

In practice you rarely need recursive querries, so gap between Logica and SQL isn't as large as it is here, but Logica is easier to read (in my opinion) for similar reasons.

Re: Logica – Declarative logic programming language for data

#64
post #62

Earlier quoted context omitted.

How do you connect to an existing database so that you can query it? There are examples of how you can specify an "engine" which will create a new database and use it as a backend for executing queries but I want to query existing data in an sqlite database.

To connect to a database file use: @AttachDatabase("db_prefix", "your_file.db"); # Then you can query from it: Q(..r) :- db_prefix.YourTable(..r);

Thank you. You can't do Q(..r) in sqlite right? That's what I read in the tutorial.

Re: Logica – Declarative logic programming language for data

#65
post #62

Earlier quoted context omitted.

To connect to a database file use: @AttachDatabase("db_prefix", "your_file.db"); # Then you can query from it: Q(..r) :- db_prefix.YourTable(..r);

Thank you. You can't do Q(..r) in sqlite right? That's what I read in the tutorial.

Ah, yes, you're right! Please do:

  # ...
  Q(your_column) :- example_db.YourTable(your_column:);
You can query multiple columns of course. Feel free to start threads in Discussions of the repo with whatever questions you have!

Re: Logica – Declarative logic programming language for data

#66

Earlier quoted context omitted.

I was turned off by this at first, but then tried it out. These are mistakes in the documentation. The tools just work with PostgreSQL and SQLite without any extra work.

How do you connect to an existing database so that you can query it? There are examples of how you can specify an "engine" which will create a new database and use it as a backend for executing queries but I want to query existing data in an sqlite database.

They are very responsive in the repo discussions, just ask questions there.

Re: Logica – Declarative logic programming language for data

#67

Earlier quoted context omitted.

> Basically, SQL syntax makes easy things easy. This gets underestimated a lot, indeed people seem to have contempt for it. I think that's a serious mistake. The flip side of that is SQL makes hard things nearly impossible. SQL doesn't have facilities for abstraction, and it doesn't compose, and this has consequences that I deal with daily. The lack of abstract facilities makes it hard to construct complicated querie…

The flip side of that is SQL makes hard things nearly impossible. What about SQL syntax makes the hard things possible? I get that the actual language SQL is broken in all sorts of ways. But I don't see any reason to replace it with some opaque from get-go. I mean, what stops you from defining, say adjectives and using those for rough modularity. Say EXPENSIVE(T) means T.price > 0; Select name FROM books WHERE EXPENS…

Yes, you can extend the language with more syntax. This kind of proves my point.

If there weren't deficiencies then you wouldn't need to define more syntax, and so many work-arounds wouldn't have already been created. The deficiencies in SQL are why each big SQL database ends up creating some procedural-SQL language for use in stored procedures and triggers.

CTEs are close to what you outline above, but even then (as far as I know) you can't name that CTE and use it across multiple statements.

Post reply on HN