News for hackers. Stuff that matters.
Re:Psql-describe: \d ported to JavaScript by darby_eight on Wednesday May 08, 2024 @01:46PM (#40300957)
This seems really cool, but also a nightmare to maintain. What are the plans for keeping this in sync with the upstream codebase?
Re:Psql-describe: \d ported to JavaScript by gmac on Wednesday May 08, 2024 @02:21PM (#40301349)
OP (and library author) here. This is a fair point, and one I freely admit to in the accompanying blog post. It’s probably not crucial to sync more than once per major Postgres version, but we’re still figuring out how we’ll deal with this.
Re:Psql-describe: \d ported to JavaScript by sroussey on Wednesday May 08, 2024 @02:19PM (#40301327)
uses emscripten to compile the C to WASM, so it’s automated.
Re:Psql-describe: \d ported to JavaScript by williamjackson on Wednesday May 08, 2024 @01:47PM (#40300964)
The fact that this is not a manual reimplementation, but a "transpilation" of the psql source from C to JavaScript, makes this super interesting to me.

    From the Postgres master branch (17devel), we take exec_command_d, exec_command_list and exec_command_sf_sv from command.c, and all of describe.c and sql_help.c, from src/bin/psql.
    We use plenty of RegExp search-and-replace to turn this C code into valid JS syntax.
    We implement some C library functions, such as strlen and strchr, and some Postgres support functions, such as printTable and printQuery, in JavaScript.
Read more here: https://neon.tech/blog/bringing-psqls-d-to-your-web-browser
Re:Psql-describe: \d ported to JavaScript by ivanjermakov on Wednesday May 08, 2024 @03:07PM (#40301781)
When I started my programming journey I thought I could just "translate" Pascal to C++ just with search/replace and minor adjustments. Turns out sometimes it's the best approach :)
Re:Psql-describe: \d ported to JavaScript by codesnik on Wednesday May 08, 2024 @01:50PM (#40300994)
I'm not sure I understand how to use that.
Re:Psql-describe: \d ported to JavaScript by gmac on Wednesday May 08, 2024 @02:23PM (#40301370)
It’s used in Neon’s web-based console to support \d and friends alongside regular SQL queries.

You might well never need to use it, but if you’re building an online query editor it could be very handy!

Re:Psql-describe: \d ported to JavaScript by theogravity on Wednesday May 08, 2024 @01:59PM (#40301091)
Yeah, I don't really get where / how I would use this. The documentation is really lacking on outlining the usage / use-case.
Re:Psql-describe: \d ported to JavaScript by arp242 on Wednesday May 08, 2024 @01:56PM (#40301062)
I always thought that most \-commands in psql were just frontends for queries? For example:

  % psql db_name
  
  (1)=# \set ECHO_HIDDEN
  
  (1)=# \d
  ********* QUERY **********
  SELECT n.nspname as "Schema",
    c.relname as "Name",
    CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' TH
  EN 'sequence' WHEN 't' THEN 'TOAST table' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'partitioned table' WHEN 'I' THEN 'partit
  ioned index' END as "Type",
    pg_catalog.pg_get_userbyid(c.relowner) as "Owner"
  FROM pg_catalog.pg_class c
       LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
       LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam
  WHERE c.relkind IN ('r','p','v','m','S','f','')
        AND n.nspname <> 'pg_catalog'
        AND n.nspname !~ '^pg_toast'
        AND n.nspname <> 'information_schema'
    AND pg_catalog.pg_table_is_visible(c.oid)
  ORDER BY 1,2;
  **************************
  
                            List of relations
   Schema │                  Name                  │   Type   │ Owner
  ────────┼────────────────────────────────────────┼──────────┼────────
  ...
I re-implemented quite a bit of that in a PostgreSQL management tool I built, based just on the ECHO_HIDDEN queries. Never even had to look at any C code.

I'm not sure if I entirely follow what translating C to JS gives you, other than a bit of (fairly simple) parsing of \cmd and flags? I didn't look too carefully at the code, so maybe I'm missing something.

Re:Psql-describe: \d ported to JavaScript by matharmin on Wednesday May 08, 2024 @03:35PM (#40302023)
If you just need one or two of the commands, just using those queries directly is easy.

If you want to support all of them, including handling all the different Postgres versions, it becomes quite a lot to implement.

Re:Psql-describe: \d ported to JavaScript by zX41ZdbW on Wednesday May 08, 2024 @03:42PM (#40302089)
In ClickHouse, \-commands correspond directly to the corresponding queries. For example, \d is SHOW TABLES, and \c is USE.

I personally don't like abbreviations and prefer full queries.

\-commands look like hacks and smell like bad practice to me. It is something from the past.

Similarly, I prefer always to write --a-long-command-line-parameter-name in my scripts instead of -wTf.

But we added shorthand commands to ClickHouse for convenience, to please Postgres users.

Re:Psql-describe: \d ported to JavaScript by arp242 on Wednesday May 08, 2024 @04:47PM (#40302578)
Almost every single post you make mentions clickhouse. You've replied to a few of my posts now with this vaguely on-topic forceful injection of clickhouse.

Of course I'm not saying you can never bring up clickhouse, but at this point it's just becoming spam. High-effort spam, maybe. But still spam.

Re:Psql-describe: \d ported to JavaScript by zX41ZdbW on Wednesday May 08, 2024 @05:38PM (#40302953)
I'm the author of ClickHouse, and this topic is interesting to me.
Re:Psql-describe: \d ported to JavaScript by arp242 on Wednesday May 08, 2024 @06:43PM (#40303466)
I am aware. But this thread is not about Clickhouse. And your comment contributed nothing to the general conversation either. The general pattern is really not appropriate.
Re:Psql-describe: \d ported to JavaScript by zX41ZdbW on Wednesday May 08, 2024 @06:54PM (#40303538)
Thank you! Let's take it as a comment about comparing styles in different database CLIs.

Some have \-commands, and some have .-commands, which I found hacky - because it is a micro language notation in addition to the actual language.

Re:Psql-describe: \d ported to JavaScript by arp242 on Wednesday May 08, 2024 @07:39PM (#40303826)
When you keep "comparing" tons of stuff to the project you wrote then you're just spamming. Like I said, this is hardly the first time I've seen it, and that's just from random posts I've seen.
Re:Psql-describe: \d ported to JavaScript by zX41ZdbW on Friday May 10, 2024 @12:17PM (#40320703)
Sorry for distracting you. My apologies.

I will try to remember your login and not answer your comments in the future. At the same time, it is possible that I will occasionally answer your comments by mistake.

Cheers, Alexey.

Re:Psql-describe: \d ported to JavaScript by millerm on Wednesday May 08, 2024 @04:56PM (#40302640)
Wow, you are right. Nice catch.
Re:Psql-describe: \d ported to JavaScript by gmac on Wednesday May 08, 2024 @02:25PM (#40301378)
Some commands issue multiple queries and include logic for stitching the results into a nice table. There’s not a one-to-one mapping from commands to queries by any means.
Re:Psql-describe: \d ported to JavaScript by arp242 on Wednesday May 08, 2024 @02:30PM (#40301428)
Yeah, that's right; but the "glue code" I've had to write for this has been really minimal. Certainly less effort than translating C to JavaScript with regexps (that on its own is something of an accomplishment). I didn't port everything so maybe I missed some more complex bits.

I mean, if this works well for you then that's grand; just wanted to point out to others that \-commands are typically very "non-magic" and you don't need to go the route of translating C code.

Re:Psql-describe: \d ported to JavaScript by gmac on Wednesday May 08, 2024 @03:03PM (#40301745)
Certainly there’s a decently long tail of rarely-used commands and obscure features of commands.
Re:Psql-describe: \d ported to JavaScript by meepmorp on Wednesday May 08, 2024 @02:03PM (#40301138)
Yeah, I don't understand why they'd translate the C code instead of just writing catalog/info schema queries, which seems easier AND more educational.
Re:Psql-describe: \d ported to JavaScript by gmac on Wednesday May 08, 2024 @05:12PM (#40302757)
OP and library author here. You’ll find the background to this in this blog post: https://neon.tech/blog/bringing-psqls-d-to-your-web-browser
Re:Psql-describe: \d ported to JavaScript by dang on Thursday May 09, 2024 @01:52AM (#40305644)
Ok, we've changed the URL to that from https://github.com/neondatabase/psql-describe above. Thanks!
Re:Psql-describe: \d ported to JavaScript by stuaxo on Thursday May 09, 2024 @04:37AM (#40306343)
Thw convertet is nice, I could imagine it being it's own library, with the generator, and a release including the generated code every postures release.
Re:Psql-describe: \d ported to JavaScript by redwood on Thursday May 09, 2024 @06:10AM (#40306718)
Anyone using Neon in prod? How is it?
Re:Psql-describe: \d ported to JavaScript by antifa on Thursday May 09, 2024 @10:25AM (#40308550)
I wish \d allowed sorting alphabetically.