Postgresql, select a "fake" row -


in postgres 8.4 or higher, efficient way row of data populated defaults without creating row. eg, transaction (pseudocode):

create table "mytable" (   id serial primary key not null,   parent_id integer not null default 1,   random_id integer not null default random(), )  begin transaction   fake_row = insert mytable (id) values (0) returning *;   delete mytable id=0;   return fake_row; end transaction 

basically i'd expect query single row parent_id 1 , random_id random number (or other function return value) don't want record persist in table or impact on primary key sequence serial_id_seq.

my options seem using transaction above or creating views copies of table fake row added don't know pros , cons of each or whether better way exists.

i'm looking answer assumes no prior knowledge of datatypes or default values of column except id or number or ordering of columns. table name known , record id 0 should not exist in table.

in past created fake record 0 permanent record i've come consider record type of pollution (since typically have filter out of future queries).

you can copy table definition , defaults temp table with:

create temp table table_name_rt (like table_name including defaults); 

and use temp table generate dummy rows. such table dropped @ end of session (or transaction) , visible current session.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -