Dialect-specific SQL
Even with the current code, take 20 will produce TOP(20), which is incompatible with some DBs.
The original plan was to allow a db named arg to queries, which I still think works well, but open to alternatives.
The original plan was to allow a db named arg to queries, which I still think works well, but open to alternatives.
What would that look like ?
The original plan was like db:postgres in the first line: https://github.com/max-sixty/prql/blob/main/examples/functions-1.md?plain=1#L2
Ahha gotcha. I had been using limit. Also should take have an optional offset parameter?
Yes I think limit might be better if we only have one, from memory.
Good idea re offset — do you want to open an issue? We could follow SQL with that and just do offset, or we could do some sort of range syntax, like other languages... (e.g. take 5..20 / take 5-20 / something better!)
Oh I like the range, I"m cool with .. I think most people are familiar with that to mean range , I'll make an issue
@qorrect
Not to stray from the point of this issue but:
Ahha gotcha. I had been using limit. Also should take have an optional offset parameter?
echo "from albums | limit 10" | prql compile
returns
Expected a known transformation; got limit
How are you utilizing limit?
Otherwise specifying the dialect in the PRQL preamble or in the CLI itself (as a flag) would be a great addition. (even though implementing dialect based sql generation seems like a huge undertaking).
Cheers.
@Akaame the PRQL keyword is actually take
echo "from albums | take 10" | prql compile
Should work. I was actually talking about under the hood in PyPrql , we use LIMIT instead of TOP in the generated SQL
The problem I had is with 'take' I got TOP (10) instead of LIMIT 10 and thought there was a 'limit' directive.
we use LIMIT instead of TOP in the generated SQL
What is the cause of the different behavior I am getting?
I think we could switch the default to LIMIT, given that's more prevalent.
And then we can do dialect-specific soon, and provide the correct one.
We now use LIMIT by default
We now use LIMIT by default, but switch to TOP if query starts with prql dialect:ms or prql dialect:microsoft or prql dialect:ms-sql-server.
prql dialect:ms_sql_server
from Employees
select [FirstName]
take 3
SELECT
TOP (3) FirstName
FROM
Employees
Currently there is no other effect of dialect, but I'm sure there should be.
@aljazerzen should we have a single name for each dialect to start? I think that might be less confusing for people confronted by an autocomplete, or sending scripts to others.
(I trust your judgement tbc, your call)
Although I do think that its a bit confusing, it can get tedious to always write dialect: ms-sql-server. That was my rationale.
In reference, we should use longer names, but I do think its quite useful to have abbreviations.
On a similar topic, do you think we should have ms-sql-server or sql-server? postgresql / postgres / postgre?
Half a p for postgres, l <--
Yeah I think it's fine to be somewhat abbreviated — mssql, postgres, mysql — etc
I think we can say this is complete, and the next part can be in https://github.com/prql/prql/issues/367, including any renames of the abbreviations.