Elektrine lite

← Feed

@c0dec0dec0de@hachyderm.io

2026-08-30 14:20 UTC

If I want to support both SQLite and Postgres, do I have to resort to having two parallel sets of scripts basically? Is there a way, inside a .sql script, to determine which database backend I’m running and branch to at least keep the parts that differ in the same file? #LazyWeb #SQL #SQLite #Postgres

Replies (4)

  • @peterrenshaw@ioc.exchange 2026-09-01 04:01

    @c0dec0dec0de@hachyderm.io You could at install. What happens as you edit the schema? There will be ways to determine a DB type at execution (PL/Python) for postgres; And via sqlite Now you have to work with three languages. Two controlling SQL choice. A simpler alternative: A make file with a TARGET?

    Open ##4592963

  • @c0dec0dec0de@hachyderm.io 2026-08-30 14:21

    Side note: it’d be cool if pgsqlite was 1) past experimental stage and probably more importantly 2) not slop…

    Open ##5116953

  • @rdnielsen@floss.social 2026-08-30 15:20

    @c0dec0dec0de@hachyderm.io If you run your SQL scripts with execsql.py (https://pypi.org/project/execsql/), you can use a system variable named CURRENT_DBMS to identify whether Postgres or Sqlite is being used. In conjunction with the IF metacommand, which works the same across all DBMSs, you can then branch to the appropriate code. Disclaimer: I wrote execsql.

    Open ##5116955

  • @benjamingeer@piaille.fr 2026-08-31 21:26

    @c0dec0dec0de@hachyderm.io You could generate the SQL from templates. But the templates might get too complicated, because there are a lot of differences.

    Open ##5116956