norm icon indicating copy to clipboard operation
norm copied to clipboard

Wildcard for Postgres

Open nixfreak opened this issue 2 years ago • 2 comments

How would I select * from table using postgres?

By reading the code I was able to actually get the select statements to work using $1

Anyway you can add some docs on using postgres?

Love your library thanks.

nixfreak avatar Jun 26 '22 20:06 nixfreak

 How would I select * from table using postgres?

select* procs in Norm always select all columns in a given table. If it has relations to other tables, it'll select the related columns as well.

So, every select is a SELECT * essentially :-)

Or maybe I'm misunderstanding your question?

moigagoo avatar Jun 29 '22 12:06 moigagoo

How would I select * from table using postgres?

By reading the code I was able to actually get the select statements to work using $1

Anyway you can add some docs on using postgres?

Love your library thanks.

Heya, As moigagoo stated, SELECT * is normal SQL syntax across all databases, so that should always work, regardless of the database.

What you might be meaning by wildcard though (and your usage of $1 indicates that to me), is placeholders, namely stuff like SELECT * FROM some_table WHERE id = ?. That is indeed different between the databases, due to their different query language, with postgres using $1 etc while sqlite uses ?. I ran into the same issue, so I believe this difference might benefit from some more visibility as well. I've pondered this, but been uncertain as to where it would be best to note this down.

A first "attempt" has already been made to make users aware of this (see #149 and its PR #150), but I myself am not too happy with it, as it might be easily missed. The main issue I have though is that writing an entire SQLite - Postgres - differences page feels a bit overkill, if all we'll put in there is the different placeholders these databases use. And if we expand that to cover all the syntax differences we'd be repeating the work that has already been done by the very capable people of each database that have written up documentation to cover the database-specific bits and bobs of their syntax.

At a glance I'm not seeing a great solution of where/how to best include that info. Anyone have any suggestions?

PhilippMDoerner avatar Jul 07 '22 19:07 PhilippMDoerner