perist sqlquery result into database? lazarus / 16-Databases ---------------------------------------------------------------------- tatamata · 2020-04-05 07:40 Hello, please suggest best way to persist an TSQLQuery result into a database (e.q PostgreSQL) table, besides creating new query with "CREATE TABLE AS..." statement? Btw, it is sqlquery without predefined fielddefs, the sql string is defined dynamically. ---------------------------------------------------------------------- eljo · 2020-04-05 10:20 SQLQuery has a number sql Statement properties 1) SQL for select 2) InsertSQL used when you call the Qry.Post method after a new record is inserted/appended. 3) UpdateSQL used when you call the Qry.Post method after a record was edited. By providing the proper sql for the two above persister sql statement you can control how the data are stored or not. ---------------------------------------------------------------------- egsuh · 2020-04-06 02:56 Try dynamically creating view, and then selecting from the view. I have started with "try" because I think this is possible theoretically, but not have done myself yet . Or you may copy it to TBufDataSet, and save the TBufDataSets as separate files. ---------------------------------------------------------------------- SamC · 2020-04-14 05:51 Hello, here are 3 simple procedures i use often to do the job: // ------------------------------------------------------------------- ----------- procedure TMainForm.buildSql(tn: String; d: TDataSet; s: TStrings); var   r: integer;   sl: TStringList; const   LIMIT = 10000; begin   sl:=TStringList.Create;   with d do begin     DisableControls;     r:=0;     first;     while not eof do     begin       // build sql-statement for insert into mysql-table       if r=0 then       begin         sl.Add(Format('replace into %s (%s)',[tn, getFieldNameList(d)]));         // sl.Add(Format('insert into %s (%s)',[tn, getFieldNameList(d)]));         sl.Add(Format(' values (%s)',[getValueList(d)]));         next;         inc(r);       end;       // build VALUES for every line in the resultset       while (not eof) and (r