Monday, October 24, 2011

Insert where not exists

I learned about this neat sql construction (it works in postgresql, I couldn't tell whether in others too):

[sourcecode language="sql"]

insert into dim_pais (pais_key,country_id,nombre) (select 0 as pais_key, 0 as country_id, 'SIN PAIS' as nombre where
not exists (select 1 from dim_pais where pais_key= 0));

[/sourcecode]

http://www.tek-tips.com/viewthread.cfm?qid=1493070

No comments:

Post a Comment