Search code examples
postgresqlquotesdefault-valuelazarussql-insert

Lazarus + PostgreSQL: Why do blank textboxes get stored with single speech marks?


The language used is Lazarus Pascal and the DB is PostgreSQL.

I'm assigning values into parameters like this:

dbQuery_Supp.Params.ParamByName('pCity').AsString := txtCity.Text;

And this is written using an INSERT query to the DB.

Data gets stored correctly for fields with values. But for text boxes that have no data, I see single quotes ('') in the fields when browsed using pgadmin.

My question:

I need to make sure that if no data is input in a textbox, the field for that value be blank in the DB instead of single quotes. Traditionally (in VB) I'd check each textbox's value and only insert it if it had data. Is this the same thing to do in Lazarus or is there a way around this? Since I'm writing the values using parameters, building a string checking for each field seems like extra work. So I'm just looking for a more efficient and convenient way if there's one.

Thanks!


Solution

  • It is pgAdmin that shows an empty string as '' in its data visualization widget. Presumably that's to distinguish it from NULL, which is by default shown as an empty box (this can be changed in the preferences).

    Compare with the output of psql if you want to be sure.